Introducing Spring Framework

Introducing Spring Framework Introducing Spring Framework

25.02.2015 Views

Chapter 11 ■ Integrating Your Spring Application with External Systems Listing 11-8. mydocuments-context.xml Listing 11-8 shows you the jmsTemplate bean that references the org.springframework.jms.core.JmsTemplate class. The JmsTemplate has a constructor where it’s being referenced to the activemqConnectionFactory bean and it has a property that will be the name of the queue, mydocumentsQueue. This will help the template to send messages to the correct destination queue. Listing 11-9 shows the modification of the previous test. 157

Chapter 11 ■ Integrating Your Spring Application with External Systems Listing 11-9. MyDocumentTest.java package com.apress.isf.spring.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.junit.FixMethodOrder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.apress.isf.java.model.Document; import com.apress.isf.java.model.Type; import com.apress.isf.java.service.SearchEngine; import com.apress.isf.java.utils.XmlUtils; import com.apress.isf.spring.amqp.RabbitMQProducer; import com.apress.isf.spring.jms.JMSProducer; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:META-INF/spring/mydocuments-context.xml") @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class MyDocumentsTest { private static final Logger log = LoggerFactory.getLogger(MyDocumentsTest.class); //Based on the META-INF/data/jms.txt - only one record private static final int MAX_ALL_DOCS = 5; private static final int MAX_WEB_DOCS = 2; @Autowired private SearchEngine engine; @Test public void testSpringJMS_1(){ log.debug("Testing Spring JMS Producer..."); jmsProducer.send(); } @Test public void testSpringJMS_2() throws InterruptedException { log.debug("Testing Spring JMS Listener/Insert..."); assertNotNull(engine); 158

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

Listing 11-8. mydocuments-context.xml<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Listing 11-8 shows you the jmsTemplate bean that references the org.springframework.jms.core.JmsTemplate<br />

class. The JmsTemplate has a constructor where it’s being referenced to the activemqConnectionFactory bean and it<br />

has a property that will be the name of the queue, mydocumentsQueue. This will help the template to send messages to<br />

the correct destination queue. Listing 11-9 shows the modification of the previous test.<br />

157

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

Saved successfully!

Ooh no, something went wrong!