1

I am working on a simple use case that would allow clients to dynamically register for events from a JMS endpoint. My current implementation looks like this:

...
public void addListener(Event event, Listener listener){
    try {
        camelContext.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from(event.from()).bean(listener);
            }
        });
    } catch (Exception exception) {
        exception.printStackTrace();
    }

}
...

event.from() above would identify the endpoint from which the message would be consumed ("activemq:topic:market.stocks.update.ibm") and listener would be an implementation of the Listener interface.

I had envisaged a typical invocation as:

notifications.addListener(updateEvent, new Listener(){
    void listen(){
        System.out.println("Hey! Something got updated");
    }
});

Except, of course, none of the above works since the camel route expects to have a concrete bean as the recipient and hence camel context fails to start-up.

What is the recommended way of adding bean end points dynamically?

calvinkrishy
  • 3,798
  • 8
  • 30
  • 45
  • hmmm, this sounds like your other question...http://stackoverflow.com/questions/6336900/design-question-on-dynamic-apache-camel-routes-context (see my comments there) – Ben ODay Jun 14 '11 at 23:23
  • This is a bit different. I would like the classic observer pattern implemented here except the callback would be performed by Camel. This would give me the advantage of not having to keep information about who is subscribed to what event (on which queue with what selectors etc.,). Also is different in a few minor aspects: The consumers are other classes in the systems and I don't care about saving the routes across restarts in this case. Its about letting interested listeners (which could be other classes in the system) know about the state change that has happened. – calvinkrishy Jun 15 '11 at 01:42
  • fair enough...thanks for the clarification – Ben ODay Jun 15 '11 at 04:12
  • FYI, this seems to work fine for me...must be an issue with your Listener class as it needs to accept a parameter type that can be converted to from a JMS message object (String, etc.) – Ben ODay Jun 16 '11 at 16:20
  • Thanks. I had posted this on the camel-users forum and figured out there was a problem in the way I had configured packageScan. http://camel.465427.n5.nabble.com/Observer-Pattern-using-Camel-td4491726.html – calvinkrishy Jun 16 '11 at 20:45

1 Answers1

2

answered on camel-users forum...

http://camel.465427.n5.nabble.com/Observer-Pattern-using-Camel-td4491726.html

Ben ODay
  • 20,784
  • 9
  • 45
  • 68