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
>> 
> 
> 
> 

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

Reply via email to