Apache Camel, Spring Remting and ActiveMQ
First of all we have this interface, just as like the base example.
package org.apache.camel.spring.remoting;
import java.rmi.Remote; public interface ISay extends Remote { |
You should put this interface somewhere in common between server and client API, e.g. common module.
package org.apache.camel.spring.remoting;
import org.apache.commons.logging.Log; public class SayService implements ISay { private final String message = “Hello”; public String say() { |
And server main class:
package org.apache.camel.spring.remoting;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class RemotingServer { |
As show above, this uses spring-server.xml descriptor file:
<?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http://www.springframework.org/schema/beans” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=” http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd”> <bean id=”sayService” class=”org.apache.camel.spring.remoting.SayService”/> <camelContext id=”camel” xmlns=”http://activemq.apache.org/camel/schema/spring”> <bean id=”activemq” class=”org.apache.camel.component.jms.JmsComponent”> |
At the end we have client main class:
package org.apache.camel.spring.remoting;
import org.springframework.context.support.ClassPathXmlApplicationContext; import java.rmi.RemoteException; public class RemotingClient { ISay say = (ISay) ctx.getBean(“sayProxy”); System.out.println(“Calling service..”); ctx.stop(); |
And client’s spring descriptor:
<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans” <camelContext id=”camel” <bean id=”activemq” class=”org.apache.camel.component.jms.JmsComponent”> </beans> |
Now all you have to do is to start ActiveMQ and enjoy.
cd ~/apache-activemq-5.0.0/bin ./activemq |
what about asynchronism? can Camel do the same stuff Lingo does with asynchronous invocations of void methods?
Amin,
Thanks for the step by step example, it helped me alot to understand things. Could you please write a simple example for usage of camel and RMI.
Thanks,
Tanveer
Very useful, the camel docs are a bit sparse in this area.
Thanks alot.