Bytekoder
Bytekoder

Reputation: 302

Apache Camel - Setting values inside Processors

I am not sure how many people have had a chance to deal with Camel Processors. So this is my concern:

I am obtaining some information and sending it to the processor. From the processor, it makes a database call via service and inserts a record. I am using a POJO and setting the values in my model in the processor via the exchange object. I am not at all facing any issues but processor is not meant for setting values in a list or any other structure. It should simply do some processing over the exchange object and pass it on primarily due to the fact that there might be a situation where multiple threads could call the same processor.

This is what I would like to know:

  1. Is there any other alternative to processors in Camel where I can do this kind setting over the model. Ex: wiretapping, interceptor etc.
  2. If not what else could be the approach?

Upvotes: 1

Views: 1704

Answers (1)

Ben ODay
Ben ODay

Reputation: 21015

Processors are singletons and therefore shouldn't be used to store state of any type...

some options...

  • store state information in the Exchange properties or Body headers

  • replace a Processor with a Bean where you can manage the scope (prototype, etc)

  • use ThreadLocal variables for non thread safe references

Upvotes: 3

Related Questions