开发者

Apache Camel routing to an interface (or rather adding listeners dynamically)

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?


answered on camel-users forum...

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜