samblake
samblake

Reputation: 1578

Custom IdempotentConsumer/Processor in Apache Camel

I want to perform custom logic in an IdempotentConsumer. I've extended the class and implemented the logic. How can I add this to my route?

Do I have to make my own Definition class? Do I add it as a Processor? How do I get the parameters passed to the constructor?

Upvotes: 1

Views: 311

Answers (1)

Milan Baran
Milan Baran

Reputation: 4232

Well, custom consumer/producer could be little overkill. I think for some kind of custom logic is enough to do it trough processor or custom bean.

1.Bean

Look at bean binding you can use simple language to pass arguments to your method. It will looks like this:

.bean(OrderService.class, "doSomething(${body}, true)")

.to("bean:orderService?method=doSomething(null, true)")

2.Processor

You have to realize your classes should be stateless because of concurrent matter of camel framework. Your constructor should be empty and your variables final otherwise whole bunch of magic could happen. Everything you want to pass to your logic component/processor should be passed via Exchange object. You can store your variables in getin() or getOut() messages as headers or body or Exchange properties and pass it to next endpoint. The exchange will change dynamically as it flows trough you camel routes. It should be your one and only one mutable object.

Upvotes: 0

Related Questions