Reputation: 3486
I have a camel route like the one showed below. How can I set up Camel to create a new instance of CodeRunner each time the route is run?
public void configure() {
from("activemq:queue:foo?asyncConsumer=true&concurrentConsumers=10")
.bean(new codeRunner(), "runCode")
.to("stream:out");
}
Upvotes: 1
Views: 293
Reputation: 855
You can just use scope="prototype" on your bean. Here some example. Route:
from("timer://foo?period=30s")
.setBody(simple("bean:test?method=getDate"))
.log(LoggingLevel.INFO, "Body:${body}");
Bean:
<bean id="test" class="my.test.package.Test" scope="prototype" />
Code:
public class Test {
final Timestamp date;
public Test() {
this.date = new Timestamp(System.currentTimeMillis());
}
public Timestamp getDate() {
return date;
}
}
Output:
2018-11-13 16:45:07,372 | INFO | #6 - timer://foo | route4 | 98 - org.apache.camel.camel-core - 2.16.3 | Body:2018-11-13 16:45:07.37
2018-11-13 16:45:37,371 | INFO | #6 - timer://foo | route4 | 98 - org.apache.camel.camel-core - 2.16.3 | Body:2018-11-13 16:45:37.37
2018-11-13 16:46:07,371 | INFO | #6 - timer://foo | route4 | 98 - org.apache.camel.camel-core - 2.16.3 | Body:2018-11-13 16:46:07.371
2018-11-13 16:46:37,375 | INFO | #6 - timer://foo | route4 | 98 - org.apache.camel.camel-core - 2.16.3 | Body:2018-11-13 16:46:37.375
Upvotes: 1