質問

I am implementing my own custom component and I have found that I am going to need two use cases for consumers:

  • The first one would be trying to get N number of available messages every so often (Polling Consumer)
  • The second one would be a subscriber consumer that gets messages when they are available.

My main question is if it possible to implement these two types. I have been trying to write some code, but it seems that if you are developing a PollingConsumer you cannot implement another type. Also, if it is possible, is there any example, article or guide about how to do this? I have been looking for it for nothing came up.

Thanks!

役に立ちましたか?

解決

There is two consumer kind in Camel (eg from the EIP book)

  • Consumer
  • PollingConsumer

Its the former that is used in the Camel routes. And the latter is used when you use it explicit or when using ConsumerTemplate, to use the receive methods.

A Camel component is able to adapt a Consumer to a PollingConsumer out of the box.

So it depends if you want to build a Camel component that are used in routes, you can just create a consumer. And have it able to do both poll and subscribe. When you have the data, then create an Exchange and call the processor to route it.

For documentation then check the Camel website, and/or chapter 11 in the Camel in Action book which covers creating custom components.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top