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

Table 11-1. RabbitMQ Namespace Definitions<br />

Tag<br />

<br />

<br />

<br />

<br />

<br />

<br />

Description<br />

This tag will handle the connections to the RabbitMQ broker; it can accept multiple<br />

properties such as username, password, virtual host, etc.<br />

This tag will help to create queues, exchanges and bindings; this is necessary to<br />

create the queue you are using, mydocumentsQueue.<br />

This tag will send messages to the RabbitMQ broker using the routing key, which in<br />

this case is the same as the queue, mydocumentsQueue. This template also is capable of<br />

receiving and converting messages, but in your case you already took care to serialize<br />

the message into an XML format by using the XMLUtils class in the producer.<br />

This tag will help to create the mydocumentsQueue; the <strong>Spring</strong> Rabbit module will<br />

attempt to create the queue only if the queue doesn’t exist.<br />

This tag will help to create a container that will be connected to the RabbitMQ<br />

broker. This tag has an embedded tag, the tag. This tag will be<br />

used at the end of the chapter.<br />

This tag declares the class that will be used as an actual listener for a message; in<br />

other words, every new message from RabbitMQ will be handled by the referenced<br />

class. This tag will be used at the end of the chapter.<br />

Next, you need to create the unit test so you can start sending messages to RabbitMQ. Listing 11-12 shows the<br />

unit test.<br />

Listing 11-12. MyDocumentsTest.java<br />

package com.apress.isf.spring.test;<br />

import static org.junit.Assert.assertEquals;<br />

import static org.junit.Assert.assertNotNull;<br />

import java.util.Date;<br />

import java.util.UUID;<br />

import org.junit.FixMethodOrder;<br />

import org.junit.Ignore;<br />

import org.junit.Test;<br />

import org.junit.runner.RunWith;<br />

import org.junit.runners.MethodSorters;<br />

import org.slf4j.Logger;<br />

import org.slf4j.LoggerFactory;<br />

import org.springframework.beans.factory.annotation.Autowired;<br />

import org.springframework.test.context.ContextConfiguration;<br />

import org.springframework.test.context.junit4.<strong>Spring</strong>JUnit4ClassRunner;<br />

import com.apress.isf.java.model.Document;<br />

import com.apress.isf.java.model.Type;<br />

import com.apress.isf.java.service.SearchEngine;<br />

import com.apress.isf.java.utils.XmlUtils;<br />

163

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

Saved successfully!

Ooh no, something went wrong!