|
Page Edited :
SM :
2.6. Beginner - Exercise
2.6. Beginner - Exercise has been edited by Jean-Baptiste Onofré (May 13, 2009). Content:In this exercise, you will have to add two service units and redeploy the service assembly by yourself. IntroductionInstead of simply copying files from one directory to the other, we are now going to send the message straight to a JMS queue. We also want to retain a copy of the original message for archiving, so we are going to use the wiretap pattern for that. Creating the projects
First of all, we have to create two additional project modules for our two new service units. Instead of using the plain servicemix-service-unit archetype as before, we are now going to use two new archetypes:
Check this page if you need help in running the archetype. These archetypes are a bit more advanced:
Afterwards, add these two new service units to the service assembly by adding the necessary <dependency/>s to the SA's pom.xml. If you want, you can also change the <name/>s to get a cleaner build log. Configure tutorial-jms-suChange the tutorial-jms-su's xbean.xml to access a queue named queue/tutorial on ActiveMQ (which is embedded in ServiceMix). <beans xmlns:jms="http://servicemix.apache.org/jms/1.0" xmlns:tut="urn:servicemix:tutorial" xmlns:amq="http://activemq.org/config/1.0">
<jms:endpoint service="tut:jms"
endpoint="myQueue"
role="provider"
destinationStyle="queue"
jmsProviderDestinationName="queue/tutorial"
connectionFactory="#connectionFactory"/>
<amq:connectionFactory id="connectionFactory" brokerURL="tcp://localhost:61616" />
</beans>
Configure tutorial-eip-suChange the tutorial-eip-su's xbean.xml to define the wiretap we need. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:eip="http://servicemix.apache.org/eip/1.0" xmlns:tut="urn:servicemix:tutorial"> <eip:wire-tap service="tut:wiretap" endpoint="endpoint"> <eip:target> <eip:exchange-target service="tut:jms" /> </eip:target> <eip:inListener> <eip:exchange-target service="tut:file" endpoint="sender" /> </eip:inListener> </eip:wire-tap> </beans> We want to forward the message exchange to the jms endpoint, so we specify that information on the first <eip:exchange-target/>. The second one refers back to the <file:sender/ Configure tutorial-file-suYou have to change the targetService on the <file:poller <file:poller service="tut:file" endpoint="poller" file="file:/home/gert/poller" targetService="tut:wiretap"/> Build and deployWhen everything is done, you are ready to build and deploy the service assembly. When you do the build, the log should be similar to this one (if the SA isn't built last, you forgot to add the necessary <dependency/> to that pom.xml file): [INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] Tutorial
[INFO] Tutorial :: File SU
[INFO] Tutorial :: JMS SU
[INFO] Tutorial :: EIP SU
[INFO] Tutorial :: SA
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...
For the deploy, you have two ways :
TestingIf you copy a file into the poller's target directory now, it will also be moved into the sender's directory, just as before. However, there should also be a copy of the message in our JMS queue. To check this, connect to ServiceMix using a JMX console (refer back to our previous tutorial if you need help doing this) and navigate the MBean tree to org.apache.activemq/localhost/Queues. A queue should have been auto-created with the name queue/tutorial and the EnqueueCount attribute is showing the number of messages that have already been sent (in our case: 1). Things to remember
Further reading
|
Unsubscribe or edit your notifications preferences
