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 />

//Waiting a least 5 seconds so the message is consumed.<br />

Thread.sleep(5000);<br />

//After the JMS message and insert, must be 5 Documents<br />

assertEquals(MAX_ALL_DOCS, engine.listAll().size());<br />

}<br />

Type documentType = new Type("WEB",".url");<br />

assertEquals(MAX_WEB_DOCS, engine.findByType(documentType).size());<br />

}<br />

Listing 11-9 shows how to run the producer and consumer. There are two methods: test<strong>Spring</strong>JMS_1 for your<br />

producer and test<strong>Spring</strong>JMS_2 for your consumer. Note that at some point you need to run the tests in order, and<br />

JUnit has no guarantee of doing that. That’s why the @FixMethodOrder annotation was added and the test methods<br />

were renamed so you can run this test and the methods will be executed in order.<br />

RabbitMQ and <strong>Spring</strong> Rabbit<br />

Now let’s do the next part where your other friend is waiting for you to send an XML message, but in this case using a<br />

AMQP (Advance Message Queue Protocol), and he or she is using the RabbitMQ broker.<br />

RabbitMQ is a messaging broker that uses AMQP, which is a wired protocol, meaning that it is not based on any<br />

API implementation like JMS (only Java can run JMS). RabbitMQ provides a platform for your application to send and<br />

receive messages and has several features, such as speed and reliability; a persistence mechanism for your messages;<br />

clustering; high availability; multiple Client APIs in different programming languages; the ability to run in many<br />

platforms, and other features.<br />

Now for your <strong>Spring</strong> application, you need to install RabbitMQ and run it (for more information about how to<br />

install RabbitMQ, see Appendix A). Make sure RabbitMQ is running by going to http://localhost:15672 in your<br />

browser. See Figure 11-6.<br />

159

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

Saved successfully!

Ooh no, something went wrong!