I have a problem receiving AMQ-Messages in a JAVA-Method. I'm routing with a Camel-Route in Spring DSL like this:
<camel:route>
<camel:from uri="activemq:foo.bar?maxConcurrentConsumers=1"/>
<camel:to uri="bean:fooService?method=handleBarEvent"/>
</camel:route>
My JAVA-Code looks like:
package my.company.service
import org.apache.activemq.Message;
import org.apache.log4j.Logger;
public class FooService {
private static final Logger LOG = Logger.getLogger(FooService.class);
public void handleBarEvent(Message in) {
LOG.info(in);
}
public void handleOtherEvent(Message in) {
LOG.info(in);
}
}
Now if I put a String
-based Message into the AMQ, I get the following Error from Camel:
org.apache.camel.component.bean.AmbiguousMethodCallException: Ambiguous method invocations possible: [
public void my.company.service.FooService.handleBarEvent(org.apache.activemq.Message),
public void my.company.service.FooService.handleOtherEvent(org.apache.activemq.Message)
]
Why is Camel not calling the defined handleBarEvent
-Method?
What type must the Method accept as input to get the whole AMQ-Message?
I tried to change the Method to public void handleBarEvent(Object in)
but then the Method just gets the String
-Body, without the Message-Headers.
Thanks for your help!
you can use the Exchange
-Class as the parameter handleBarEvent(Exchange exchange)
and Camel will pass the full message/headers as expected...
exchange.getIn().getBody()
to get the message body exchange.getIn().getHeader([headerName])
to get a header value, etc also, you can use bean binding in more explicit ways to bind body/headers to parameters directly like this...
public String hello(String name, @Header("country") String country) {
return "Hello " + name + " you are from " + country;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.