Thanks as always, Claus. Correct, I will want to unregister / close the listener's connection upon shutdown.
Correct, I don't want to create the ProducerTemplate over and over. I'll do it once at initialization. I'll look into what it takes to create a custom component, but in the meantime, what is the best way to detect a graceful shutdown? I'm running in Spring Boot. I found an example where you could have your class implement "SmartLifecycle". Is that the best way or is there some annotation I can use to detect a shutdown (sort of like the @PostConstruct upon startup) ? Thanks again. > On 06/22/2020 12:57 AM Claus Ibsen <[email protected]> wrote: > > > Hi > > I would consider writing a custom component. As dont you also need to > unregister your listener when your app shuts down? > All of the lifecycle and management of this can be built into the > component and then as end user it becomes easier to use as its just > like another Camel endpoint. > > And btw in your sample code, then you should only create the producer > template once - not per message. > > Also as alternative you can use Camels POJO routing to hide some of Camel > https://camel.apache.org/manual/latest/pojo-producing.html > > > On Sun, Jun 21, 2020 at 11:41 PM Ron Cecchini <[email protected]> wrote: > > > > 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. > > > > -- > Claus Ibsen > ----------------- > http://davsclaus.com @davsclaus > Camel in Action 2: https://www.manning.com/ibsen2
