Versions Compared

Key

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

...

Pattern

Description

Message Channel

We need a channel so the Clients can communicate with the server.

Message

The information is exchanged using the Camel Message interface.

Message Translator

This is where Camel shines as the message exchange between the Server and the Clients are text based strings with numbers. However our business service uses int for numbers. So Camel can do the message translation automatically.

Message Endpoint

It should be easy to send messages to the Server from the the clients. This is achieved with Camels Camel's powerful Endpoint pattern that even can be more powerful combined with Spring remoting. The tutorial has clients using each kind of technique for this.

Point to Point Channel

The client and server exchanges exchange data using point to point using a JMS queue.

Event Driven Consumer

The JMS broker is event driven and is invoked when the client sends a message to the server.

...

First we need to have dependencies for the core Camel jars, its spring, jms components, and finally ActiveMQ as the message broker.

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/examples/camel-example-spring-jms/pom.xml}
As we use spring xml configuration for the ActiveMQ JMS broker we need this dependency:
Wiki Markup
{snippet:id=e2|lang=xml|url=camel/trunk/examples/camel-example-spring-jms/pom.xml}

...

For this example the Spring service (= our business service) on the server will be a simple multiplier which trebles in the received value.

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/server/Multiplier.java}
And the implementation of this service is:
Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/examples/camel-example-spring-jms/src/main/java/org/apache/camel/example/server/Treble.java}
Notice that this class has been annotated with the @Service spring annotation. This ensures that this class is registered as a bean in the registry with the given name multiplier.

...

The proxy will create a proxy service bean for you to use to make the remote invocations. The serviceInterface property details which Java interface is to be implemented by the proxy. The serviceUrl defines where messages sent to this proxy bean will be directed. Here we define the JMS endpoint with the "numbers" queue we used when working with Camel template directly. The value of the id property is the name that will be the given to the bean when it is exposed through the Spring ApplicationContext. We will use this name to retrieve the service in our client. I have named the bean multiplierProxy simply to highlight that it is not the same multiplier bean as is being used by CamelServer. They are in completely independent contexts and have no knowledge of each other. As you are trying to mask the fact that remoting is being used in a real application you would generally not include proxy in the name.

...