-
1. Re: ActiveMQ consumer id
garethahealy Dec 13, 2012 10:18 AM (in response to garethahealy)I noticed on the web console (http://localhost:8161/admin/queueConsumers.jsp?JMSDestination=ROUTE) that theres a session id. I think i might be able to use this...just need to figure out how to get it from my camel route.
-
2. Re: ActiveMQ consumer id
davsclaus Dec 13, 2012 11:17 AM (in response to garethahealy)If you use JMS message groups, then any consumer is processing the message within same group in sequence.
So if the username is the message group, then the username "foo" is only processed by one consumer, even if you have multiple routes / cluster etc.
http://activemq.apache.org/message-groups.html
http://activemq.apache.org/how-do-i-preserve-order-of-messages.html
-
3. Re: ActiveMQ consumer id
garethahealy Dec 13, 2012 12:59 PM (in response to davsclaus)Claus,
I think this might fit my situation, i'll go down this route and see if it works. It was the managing of the groups i didnt want to do. i.e.: the producer has to cycle through each "group" and set it on the outbond message.
I'd hoped there was a key/property that the camel route could access on the consumer, which would tell it which consumer the message had came off.
i.e.: Message1 was handled by Consumer1
Message2 was handled by Consumer2
Message3 was handled by Consumer1
Message4 was handled by Consumer2
and so on...
-
4. Re: ActiveMQ consumer id
davsclaus Dec 14, 2012 2:43 AM (in response to garethahealy)On the Camel Exchange API there is a getFromEndpoint, which tells you which endpoint created the Exchange, and thus also the consumer (eg as thats the endpoint created the consumer).
Also if you assign route ids then you can get the getFromRouteId as well. See the javadoc
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/Exchange.html
-
5. Re: ActiveMQ consumer id
garethahealy Dec 14, 2012 4:26 AM (in response to davsclaus)From what you are saying, it doesnt sound like theres a quick/easy inbuilt way. Below is an example of what i am doing, just to better clarify the problem.
Route that produces the message:
Route that consumes the message:
RouteDefinition route = new RouteDefinition();
route.from("activemq:Consumer.VendaUAT.VirtualTopic.sendStockToExternalServices")
.unmarshal(jsonUnmarshalInventoryChangedRequest)
.doStuff();
ActiveMQ Component setup:
ConcurrentConsumer2 has Message2
...
I'll have a play around with groups anyways, and report back with what i end up with.
-
6. Re: ActiveMQ consumer id
garethahealy Dec 19, 2012 8:50 AM (in response to garethahealy)For anyone whos interested. I went with the following solution:
();
Integer i = 0;
while (i < consumerCount) {
String stockFrontendNameConsumer = "VendaUAT_Consumer" + i;
String consumerEndpointUri = "activemq:" + stockFrontendNameConsumer;
RouteDefinition consumerRoute = new RouteDefinition();
consumerRoute.from(consumerEndpointUri)
.unmarshal(jsonUnmarshalInventoryChangedRequest)
.beanRef("addStock_Venda", "sendToFrontend")
.routeId(stockFrontendNameConsumer);
context.addRouteDefinition(consumerRoute);
consumerEndpoints.add(consumerEndpointUri);
i++;
}
RouteDefinition entryRoute = new RouteDefinition();
entryRoute.from("activemq:Consumer.VendaUAT.VirtualTopic.sendStockToExternalServices")
.loadBalance()
.roundRobin()
.to(consumerEndpoints.toArray(new String{consumerEndpoints.size()}))
.routeId("stockUpdateFor_VendaUAT");
context.addRouteDefinition(entryRoute);
This means i end up with a number of individual queues, that are load balanced.
Cheers.