Spring RemotingWe support Spring Remoting It also means we can use Content Based Router and the other Enterprise Integration Patterns in between the beans; in particular we can use Message Translator to be able to convert what the on-the-wire messages look like in addition to adding various headers and so forth. Using Camel Spring RemotingIn your Spring XML just use the CamelProxyFactoryBean Then to implement the service you use CamelServiceExporter The following example <!-- Creates a proxy to the direct:say endpoint. --> <bean id="sayProxy" class="org.apache.camel.spring.remoting.CamelProxyFactoryBean"> <property name="serviceUrl" value="direct:say"/> <property name="serviceInterface" value="org.apache.camel.spring.remoting.ISay"/> </bean> Then we expose the service on an endpoint so that messages from direct:sayImpl will be dispatched to the service (note that we have a route in between these two endpoints). <!-- Exposes the above bean as via the pojo:say endpoint --> <bean id="say" class="org.apache.camel.spring.remoting.CamelServiceExporter"> <property name="uri" value="direct:sayImpl"/> <property name="service"> <bean class="org.apache.camel.spring.remoting.SayService"/> </property> <property name="serviceInterface" value="org.apache.camel.spring.remoting.ISay"/> </bean> Using Custom NamespacesIn this example <!-- Creates a proxy to the direct:say endpoint. --> <camel:proxy id="sayProxy" serviceUrl="direct:say" serviceInterface="org.apache.camel.spring.remoting.ISay"/> Then we expose the service via the export element <bean id="sayService" class="org.apache.camel.spring.remoting.SayService"/> <camel:export id="say" uri="direct:sayImpl" serviceRef="sayService" serviceInterface="org.apache.camel.spring.remoting.ISay"/> Its much cleaner - use whichever approach you prefer as they are both equivalent. ServiceExporter is OptionalNote that the service is not mandatory; since the Bean component and the various other forms of Bean Integration can be used to route any message exchange to a bean, so you can miss out the serviceExporter if you prefer. The main value of the service exporter is its a single XML element to bind a URI to a bean and it allows the full API of the bean to be restricted by a serviceInterface. Working with InOnly method callsAs of 1.5 Camel supports the @InOnly and @Pattern annotations to let you specify which methods are not InOut (Request Reply) but are InOnly (oneway or fire and forget Event Message). For more details see Using Exchange Pattern Annotations Bean BindingThe Bean Binding in Camel defines both which methods are invoked and also how the Message is converted into the parameters of the method when it is invoked. Choosing the method to invokeThe binding of a Camel Message to a bean method call can occur in different ways
By default the return value is set on the outbound message body. Binding AnnotationsYou can use the Parameter Binding Annotations to customize how parameter values are created from the Message ExamplesFor example a Bean such as: public class Bar { public String doSomething(String body) { // process the in body and return whatever you want return "Bye World"; } Or the Exchange example. Notice that the return type must be void: public class Bar { public void doSomething(Exchange exchange) { // process the exchange exchange.getIn().setBody("Bye World"); } For example you could use POJO Consuming to write a bean like this
public class Foo { @MessageDriven(uri = "activemq:my.queue") public void doSomething(String body) { // process the inbound message here } } Here Camel with subscribe to an ActiveMQ queue, then convert the message payload to a String (so dealing with TextMessage, ObjectMessage and BytesMessage in JMS), then process this method. |