25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11 ■ Integrating Your <strong>Spring</strong> Application with External Systems<br />

Figure 11-1 shows how the My Documents application will interact with JMS. There will be a producer that only<br />

talks JMS, and it will send messages to a JMS container, in this case Apache ActiveMQ. Then My Documents, after<br />

receiving the message in a String XML format, will save it into the database; after that it will send the same message<br />

but using AMPQ to the RabbitMQ broker. You are going to create both the producer and consumer for the JMS and a<br />

producer and consumer for the AMQP.<br />

Java Message Service<br />

Let’s start by setting My Documents up to receive XML messages from a JMS service. But wait, what is this JMS thing?<br />

The Java Message Service API was developed by the Java community (JSR 914) as an effort to connect different and<br />

distributed clients (MOM—message-oriented middleware) in an asynchronous way and loosely couple. The clients<br />

can send and receive messages in a point-to-point (queues) or a publish-subscribe (topics) way.<br />

To emulate your friend that only talks to JMS, you are going to install Apache ActiveMQ. This is a JMS container.<br />

You can download it from http://activemq.apache.org/. (For more information about how to install<br />

ApacheMQ, see Appendix A.)<br />

Listing 11-1 shows the XML that you are going to use to send document information to your <strong>Spring</strong> application.<br />

The XML contains some documentIds, a name, location, description, the date created and modified, and the type with<br />

its attributes.<br />

Listing 11-1. XML Document Info (META-INF/data/jms.txt)<br />

<br />

df569fa4-a513-4252-9810-818cade184ca<br />

Apress Books<br />

<br />

4980d2e4-a424-4ff4-a0b2-476039682f43<br />

WEB<br />

Web Link<br />

.url<br />

<br />

http://www.apress.com<br />

Apress Books<br />

2014-03-11 03:02:18.490 UTC<br />

2014-03-11 03:02:18.490 UTC<br />

<br />

Next, start the Apache ActiveMQ, go to the main page (http://localhost:8161/hawtio), and create a queue<br />

(destination) with the name of mydocumentsQueue. On the Hawtio web page, go to the left side and select the<br />

localhost node. Some tabs will appear; select the + Create tab. It will display a Create Queue dialog. Set the name<br />

and choose the Queue option, then click the Create Queue button. See Figure 11-2.<br />

146

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!