Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

MINA has been configured to send over the wire objects serialized and this is what is showed also in this example.
The advantage of this approach is that you don't need to use CORBA or Java RMI for the communication between the different JVMs.
The example has been configured to use InOut EIP pattern (sync=true on the Mina endpoint).

The demo starts when every one minute, a Report object is created from the camel loadbalancer server. This object is send by the
camel loadbalancer to a MINA server and object is serialized. One of the two MINA servers (localhost:9999 and localhost:9998) receives
the object and enrich it by setting the field reply of the Report object. The reply is send back by the MINA server to the waiting caller,
who will display in its log the content of the Report object.

...

Code Block
xml
xml
titleLoad balancer (the caller)
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:camel="http://camel.apache.org/schema/spring"
 xsi:schemaLocation="
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 http://camel.apache.org/schema/spring
 http://camel.apache.org/schema/spring/camel-spring.xsd ">
 
<bean id="service" class="org.apache.camel.example.service.Generator"/> 

<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">

    <package>
        com.intuit.ai.step.camel 
    </package><!-- this is just a route to auto generate sample reports -->
    <route id="sendMessage">
    	<from uri="timer://org.apache.camel.example.loadbalancer?fixedRate=true&amp;period=60000"/>
    	<bean ref="service" method="createReport"/>
    	<to uri="direct:loadbalance"/>
    </route>
    
    <!-- this is the route with the load balancer which sends in round robin to the 2 mina endpoints -->
    <route id="loadbalancer">
        <from uri="direct:loadbalance"/>
        <loadBalance>
            <roundRobin/>
            <to uri="mina:tcp://localhost:9999?sync=true&amp;allowDefaultCodec=true"/>
            <to uri="mina:tcp://localhost:9998?sync=true&amp;allowDefaultCodec=true"/>
        </loadBalance>
        <to uri="log:org.apache.camel.example?level=INFO"/>
    </route>

</camelContext>

</beans>
Code Block
xml
xml
titleMina Server 1
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:camel="http://camel.apache.org/schema/spring"
 xsi:schemaLocation="
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 http://camel.apache.org/schema/spring
 http://camel.apache.org/schema/spring/camel-spring.xsd ">
 
<bean id="service" class="org.apache.camel.example.service.Reporting"/> 

<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
    <route id="mina1">
        <from uri="mina:tcp://localhost:9999"/>
        <setHeader headerName="minaServer"><constant>localhost:9999</constant></setHeader>
		<bean ref="service" method="updateReport"/>
    </route>
</camelContext>

</beans>

...