25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 16 ■ Messaging with Your <strong>Spring</strong> Application<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Listing 16-10 shows all the necessary information (like the location of the RabbitMQ server; the name of queues<br />

and their bindings with the exchange; the message converter and the consumers) that RabbitMQ needs in order to<br />

start sending, converting, and receiving messages. This configuration can be done using the RabbitMQ web console<br />

or it can be done programmatically, offering more control depending on certain business rules, but here you are going<br />

to use the <strong>Spring</strong> XML configuration, the declarative way. If you want to see how you can do all of this configuration<br />

programmatically, you can take a look at the RabbitMQ reference at http://docs.spring.io/spring-amqp/docs/<br />

latest-ga/reference/html/.<br />

This configuration (see Listing 16-10) has several sections; let’s take a look at each one of them. Remember that<br />

you are using the namespace.<br />

<br />

The tag will create a caching connection to the RabbitMQ broker and you can pass<br />

some extra information like username, password, host, vhost, and port.<br />

The tag will create all the necessary exchanges, bindings, and queues, and it is necessary to<br />

pass the ID of the connection (rabbitConnectionFactory).<br />

<br />

The tag is an implementation of the Template pattern, and this will help to send and convert<br />

messages to the RabbitMQ broker. You need to specify what connection you are going to use to pass the ID of the<br />

connection-factory (rabbitConnectionFactory) and the converter that you are going to use (messageConverter); in<br />

this case, it’s the Marshaller defined in Listing 16-9.<br />

225

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

Saved successfully!

Ooh no, something went wrong!