Reputation: 133
I need to implement a custom PollingConsumerPollStrategy
implementation on a route inside a RouteBuilder
. The examples I found use spring to create a bean, but i am not using Spring in my project.
How do i add MyPollStrategy
to registry and use it as pollStrategy=#myPoll ?
public class MyFtpServiceBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
// Want to add to below route &pollStrategy=#myPoll
from("sftp://tmpserver.example.com:22//tmp/testfolder?password=xxxxxx&username=tmpuser")
.routeId("testRoute")
.to("file:C:/tmp/testfolder")
}
private class MyPollStrategy implements PollingConsumerPollStrategy {
public boolean begin(Consumer consumer, Endpoint endpoint) {
return true;
}
public void commit(Consumer consumer, Endpoint endpoint, int polledMessages) {
if (polledMessages > maxPolls) {
maxPolls = polledMessages;
}
latch.countDown();
}
public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception cause) throws Exception {
return false;
}
}
}
Upvotes: 2
Views: 5488
Reputation: 133
As i was using the org.apache.camel.main.Main
, I could not figure out a way to create a SimpleRegistry as Claus mentioned and pass it to the main object.
Just found out that there is a method bind
in Main
class to pass bean name and bean object.
Main main = new Main();
main.addRouteBuilder(new MyTestRouteBuilder());
main.enableHangupSupport();
main.bind("myPoll", new MyPollStrategy());
main.run();
Upvotes: -1
Reputation: 55535
You can create an instance of SimpleRegistry
where you can add your custom bean. And then pass in the simple registry instance to where you create CamelContext with the new DefaultCamelContext(myRegistry)
constructor.
If you have a copy of Camel in Action book, see the beans chapter, it explain all about this in more details.
On the web site there is a little details at: http://camel.apache.org/registry.html
Upvotes: 3