Example

The Lingo test suite includes a simple example demonstrating the various message exchange patterns using simple Spring POJOs.

You can browse the code for the example here.

You just need to configure the client side proxy in a similar way to other remoting options in Spring. Then on the server side you need to expose a service - again using a service exporter like other remoting options in Spring.

There's an example configuration file of both client and server sides here

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

  <!-- client side proxy-->
  <bean id="client" class="org.logicblaze.lingo.jms.JmsProxyFactoryBean">
    <property name="serviceInterface" value="org.logicblaze.lingo.example.ExampleService"/>
    <property name="connectionFactory" ref="jmsFactory"/>
    <property name="destination" ref="exampleDestination"/>
  </bean>

  <!-- the server side -->
  <bean id="server" class="org.logicblaze.lingo.jms.JmsServiceExporter">
    <property name="service" ref="serverImpl"/>
    <property name="serviceInterface" value="org.logicblaze.lingo.example.ExampleService"/>
    <property name="connectionFactory" ref="jmsFactory"/>
    <property name="destination" ref="exampleDestination"/>
  </bean>

  <!-- the actual implementation of the service - which is only made public for testing purposes -->
  <bean id="serverImpl" class="org.logicblaze.lingo.example.ExampleServiceImpl" singleton="true"/>


  <!-- JMS ConnectionFactory to use -->
  <bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="vm://localhost"/>
  </bean>

  <bean id="exampleDestination" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg index="0" value="test.org.logicblaze.lingo.example"/>
  </bean>
</beans>

Then in your Java code, just lookup the client in Spring (or preferably have it dependency injected into your code by Spring) and then just use it as a regular POJO.

// lets lookup the client in Spring
// (we could be using DI here instead)
ExampleService service = (ExampleService) getBean("client");

// regular synchronous request-response
int i = service.regularRPC("Foo");
System.out.println("Found result: " + i);

Labels

 
(None)