camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ashwin Karpe <aska...@progress.com>
Subject Re: How to route a message to remote ActiveMQ broker(s) dynamically?
Date Tue, 20 Apr 2010 16:09:05 GMT

Hi,

A better approach would be to create connection objects for the remote
brokers and have them stored in JNDI or LDAP (if it is an embedded broker,
have the app creating the broker store a connection object in JNDI/LDAP).

The camel route can then simple grab a reference and send a message to the
endpoint.

You have a very interesting/non-traditional use-case here. Creating these
connections on the fly in a camel route may not be the best approach.
Providing an ability to select the best/optimal connection object and
invoking on it is the better and more scalable way forward.

Hope this helps.

Cheers,

Ashwin...  



mdasari wrote:
> 
> Thanks Willem for your comments. I posted a simpler version of my code. My
> actual code was adding a camel Component (ActiveMQComponent) by using
> CamelContext.addComponent and I'm trying to retrieve the component by
> calling getComponent. The key is hash of the IP address,  basically like 
> CamelContext::getOrCreateComponent. At the moment it seems to be creating
> a new component every time though. I can work around by my own cache or
> some other means. 
> 
> But my real issue is usage of wrong IP address for delivery of the
> messages, it must be caching the first Endpoint there some where and using
> it again and again.
> 
> I tried with version 1.6.2 there is no change in the behavior. I wonder if
> there is something wrong with my usage of Endpoint. 
> 
> Are there any other ways of implementing remote broker RecipientList EIP?
> 
> cheers
> - mdasari
> 
> 
> 
> willem.jiang wrote:
>> 
>> You created a new CamelContext and a ActiveMQComponent( for each new 
>> endpoint, that are expensive operation, maybe you can use a 
>> ActiveMQComponent cache with IPAddress as the index.
>> 
>> Can you try to use the latest released version of Camel 1.x (Camel 
>> 1.6.2) to see if the issue still there?
>> 
>> Willem
>> 
>> mdasari wrote:
>>> Hi,
>>> 
>>> I needed to route a message from one ActiveMQ broker to one or more
>>> remote
>>> ActiveMQ brokers based on some runtime information.
>>> 
>>> Lets say I've broker "central" and remote brokers "remote1", "remote2",
>>> ...
>>> "remoteN".
>>> The number of remote brokers can change over time and I wouldn't want to
>>> configure any beans or any kind of configuration in the activemq.xml of
>>> the
>>> "central" broker.
>>> 
>>> The following what I tried, but it seems to be sending the message
>>> always to
>>> the first "remote" server that I used. Couple of points:
>>> 
>>> 0. I putup a POJO  bean with RecipientList EIP.
>>> 1. topic:Out.RemoteServers is the topic on the "central" broker
>>> 2. topic:In.LocalServer is the topic on any "remote" broker.
>>> 3. All applications that post messages to "central" broker add a message
>>> header with name "IPAddesses". The header value contain a list of IP
>>> addresses corresponding to the "remote" brokers.
>>> 4. I'm using camel version 1.6.1.0
>>> 
>>> The code looks as follows (trimmed for clarity)
>>> 
>>> --------
>>> 	@Consume(uri = "topic:Out.RemoteServers")
>>> 	@RecipientList()
>>> 	public Collection<Endpoint> getRoutes(@Header(name = "IPAddresses")
>>> String
>>> ips, String body) {
>>> 		List<Endpoint> dests = new ArrayList<Endpoint>();
>>> 		try {
>>> 			// do some validation on IP addresses header and barf.
>>> 
>>> 			// The header is delimited by commas.
>>> 			//
>>> 			StringTokenizer tokenizer = new StringTokenizer(ips, ",");
>>>   		
>>> 			CamelContext ctx = new DefaultCamelContext();
>>> 			while (tokenizer.hasMoreElements()) {
>>> 				String ip = tokenizer.nextToken();
>>> 				ActiveMQComponent amq = new ActiveMQComponent(ctx);
>>> 				
>>> 				logger.info("Setting the broker URL to IP: " + ip);
>>> 				
>>> 				amq.setBrokerURL("tcp://" + ip + ":61616");
>>> 
>>> 				Endpoint ep = amq.createEndpoint("activemq:topic:In.LocalServer");
>>> 				dests.add(ep);
>>> 			}
>>> 		} catch (Exception e) {
>>> 		            // Let our monitoring take care of this..
>>> 			logger.error("Unexpected exception while routing.", e);
>>> 		}
>>> 		return dests;
>>> 	}
>>> 
>>> ----
>>> 
>>> Appreciate any help.
>>> 
>>> cheers
>>> - mdasari
>>> 
>> 
>> 
>> 
> 
> 


-----
--- 
Ashwin Karpe, Principal Consultant, PS - Opensource Center of Competence 
Progress Software Corporation
14 Oak Park Drive
Bedford, MA 01730
--- 
+1-972-304-9084 (Office) 
+1-972-971-1700 (Mobile) 
---- 
Blog: http://opensourceknowledge.blogspot.com/


-- 
View this message in context: http://old.nabble.com/How-to-route-a-message-to-remote-ActiveMQ-broker%28s%29-dynamically--tp28273566p28287892.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message