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

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

154<br />

<br />

<br />

In Listing 11-5, the ActiveMQConnectionFactory class was added because it will help to connect to<br />

the Apache ActiveMQ broker. Normally it will only require the broker’s URL. However, in this case, because you<br />

are running it locally, it will be tcp://localhost:6161. Then a new namespace was also added;<br />

with this namespace you can add the tag that makes a reference to the connection<br />

factory and where you are referencing the JMSConsumer class (Listing 11-2) by using the tag. The<br />

tag has a reference to the name of the queue, mydocumentsQueue. This tag will start listening to the<br />

mydocumentsQueue for any new incoming message and they will be delivered to the onMessage method.<br />

Next, let’s see the test class (see Listing 11-6) and run it.<br />

Listing 11-6. 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 org.junit.Ignore;<br />

import org.junit.Test;<br />

import org.junit.runner.RunWith;<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 />

import com.apress.isf.spring.amqp.RabbitMQProducer;<br />

import com.apress.isf.spring.jms.JMSProducer;

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

Saved successfully!

Ooh no, something went wrong!