Sunday 15 April 2012

java - Using camel to aggregate messages of same header -


I have several clients who send files to a server, containing information about that data for a set of data There are two files, each with the same name. When a file has been received, the server sends a message in my queue that contains the file path, file name, the customer ID, and the "type" of the file (all have the same file extensions, but two "types," they have A and B Say.)

Two files for a set of data are the same file names. As soon as the server has received both files, I need to start a program that combines two. I currently have something like this that looks like this:

  ("jms: queue.name"). Total (header ("camelfileName") Completion (2) .to ("exec: // filePage arg =");   

Where I'm stuck is the header ("camerafilename"), and more specifically how the aggregator works.

Complete sets 2 sets, it just sucks all the messages and stores them in some data structure, until the second message that comes in is already matched? Also, the header () is expected of a specific value? I have many clients, so I was thinking of putting the client ID and the file name at the top, but then I do not know that I have to give a specific value. I do not even know if I can use a regex or not.

Any ideas or suggestions will be super helpful thanks

EDIT: Here are some codes I have based on my description of this problem and on the basis of comments on the selected answer It looks accurate (except for closed brackets, which I have not copied)?

  Public static zero master throws exception {] {CamelContext c = new DefaultCamelContext (); C.addComponent ("activemq", activeMQComponent ("vm: // localhost? Broker.persistent = false")); // ActiveMQConnectionFactory ConnectionFeature = New ActiveMQConnectionFactory ("vm: // localhost? Broker.persistent = false"); //c.addComponent (frames), JmsComponent.jmsComponentAutoAcknowledge (connectionFactory)); C.addRoutes (new route-builder (public (not configured) (from "activemq: queue: analytics.camelqueue") Total (New MyAggregationStrategy ()). Header ("Subject"). "Activemq: Queue: analytics Success ");}}); C.start (); While {true} {System.out.println ("Waiting for incoming messages for camels"); Thread Sleep (2 * 1000); } // .stop (); } Private Static Class MyAggregationStrategy applies AggregationStrategy {public exchange total (Exchange old exchange, Exchange NewX change) {if (oldExchange == null) newExchange; // and here it is where the combo stuff gets the string old body = old exchange.Getine (). GetBody (String.class); String newBody = newExchange.getIn (). GetBody (String.class); Boolean oldset = oldbild canteen ("set"); Boolean newSet = newBody.contains ("set"); Boolean old flow = oldbild canteen ("flow"); Boolean newflow = newbodicon ("flow"); If (old flows and newsstand)) (// they match, then return new exchange with information so that the extractor is combined with string joint = old body + "\ n" + newBody Can be started + "\ N"; NewExchange.getIn () setBody (combined). Return new exchange; } And {// none match. .... return tap; }}}}  

You must supply aggregation strategy to define how you want to add exchanges. ..

If you are interested only in the filename and you are receiving 2 exchanges then you can use only "Integrated" to pass the latest exchange through only one bar. You can use UseLatestAggregationStrategy for ...

He said, it seems that you need to retain both exchanges (one for each customer ID) so that you can get the information 'Exclusive 'Can pass in phase ... if If so, you can add exchanges to a grouped exchange, though the holder has been enabled using the groupExchanges option ... or specifically custom aggregation strategy using the built-in aggregation strategy. You will like them just to keep in mind that whatever you decide to use the 'comp' phase, you need to handle it ...

For example See these unit tests:



No comments:

Post a Comment