Reputation: 385
I am trying to invoke a different service depending on the bean input. But my instance service is not getting invoked. Please find the code below:
My Route
from("jms:queue:instance").filter()
.method(instanceTypeFilter, "isMCUInstance")
.to("instanceservice").filter()
.method(instanceTypeFilter, "isDMAInstance")
.to("instanceservice").filter()
.method(instanceTypeFilter, "isWSPInstance")
.to("instanceservice").filter()
.method(instanceTypeFilter, "isMEAInstance")
.to("instanceservice").filter()
.method(instanceTypeFilter, "isRSSInstance")
.to("instanceservice");
Below method calls is getting invoked
public class InstanceTypeFilter {
public boolean isMCUInstance(Instance instance) {
System.out.println("Entering : InstanceTypeFilter : isMCUInstance");
System.out.println("instance.getType() : " + instance.getType());
return instance.getType() == "MCU";
......................
}
But below code is not getting invoked
Service(value = "instanceservice")
public class InstanceServiceImpl implements InstanceService {
public Instance add(final Instance instance) {
System.out.println("Entering : InstanceServiceImpl : add");
instance.setId("newId");
instance.setName("newName");
instance.setType("newType");
System.out.println("Exiting : InstanceServiceImpl : add");
return instance;
}
}
I am a bigginner to Camel, as for as i understood, add method should get executed. I am using proxy with spring remoting for invoking add method.
I tried like below, but still the problem persists
.when(method(InstanceTypeFilter.class, "isMCUInstance")
.isEqualTo(true))
.to("instanceservice")
.when(method(InstanceTypeFilter.class, "isDMAInstance")
.isEqualTo(true))
.to("instanceservice")
.when(method(InstanceTypeFilter.class, "isWSPInstance")
.isEqualTo(true))
.to("instanceservice")
.when(method(InstanceTypeFilter.class, "isMEAInstance")
.isEqualTo(true))
.to("instanceservice")
.when(method(InstanceTypeFilter.class, "isRSSInstance")
.isEqualTo(true)).to("instanceservice");
Upvotes: 0
Views: 116
Reputation: 4667
Instead of .to("instanceservice")
try using .to("bean:instanceservice?method=add")
or .beanRef("instanceservice", "add")
;
Upvotes: 0
Reputation: 55535
You should use the content based router instead of the filter eip
The EIPs is listed here with examples http://camel.apache.org/eip
The EIP you are looking for is here http://camel.apache.org/content-based-router.html
The content based router is just like a if .. else if .. else if ... else control structure in any programming language.
Upvotes: 1