Hi guys. I have to integrate a 3rd party’s message listener code into my
routes. Their API is pretty simple:
listener(“foo”, fooHandler());
creates a listener using the underlying configured JMS and calls fooHandler()
whenever it sees a “foo“ message.
Instead of creating a full-blown Camel component (something that I’ve never
done yet) which would allow me to do something like:
from(“mylistener:foo“).bean(fooProcessor)
I was thinking about doing something simpler and creating a class that calls
listener() and where the handler injects the messages into a “direct:foo”
route. Something like:
class FooListener
{
@PostConstruct
void initialize()
{
listener("foo", fooHandler();
}
void fooHandler(msg)
{
ProducerTemplate template = context.createProducerTemplate();
template.asyncSendBody("direct:foo", msg);
}
}
and then have a route like:
from("direct:foo").bean(fooProcessor);
So, is this a dumb approach? I realize creating a custom component would be
nicer and more easily reusable, but are there any other major pros and cons?
Thanks.