Search in sources :

Example 26 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project camel by apache.

the class JmsJMSReplyToEndpointUsingInOutTest method testCustomJMSReplyToInOut.

@Test
public void testCustomJMSReplyToInOut() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("My name is Arnio");
    // do not use Camel to send and receive to simulate a non Camel client
    // use another thread to listen and send the reply
    ExecutorService executor = Executors.newFixedThreadPool(1);
    executor.submit(new Callable<Object>() {

        public Object call() throws Exception {
            JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
            final TextMessage msg = (TextMessage) jms.receive("nameRequestor");
            assertEquals("What's your name", msg.getText());
            // there should be a JMSReplyTo so we know where to send the reply
            final Destination replyTo = msg.getJMSReplyTo();
            // send reply
            jms.send(replyTo, new MessageCreator() {

                public Message createMessage(Session session) throws JMSException {
                    TextMessage replyMsg = session.createTextMessage();
                    replyMsg.setText("My name is Arnio");
                    replyMsg.setJMSCorrelationID(msg.getJMSCorrelationID());
                    return replyMsg;
                }
            });
            return null;
        }
    });
    // now get started and send the first message that gets the ball rolling
    JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
    jms.send("hello", new MessageCreator() {

        public Message createMessage(Session session) throws JMSException {
            TextMessage msg = session.createTextMessage();
            msg.setText("Hello, I'm here");
            return msg;
        }
    });
    assertMockEndpointsSatisfied();
    executor.shutdownNow();
}
Also used : Destination(javax.jms.Destination) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ExecutorService(java.util.concurrent.ExecutorService) JmsTemplate(org.springframework.jms.core.JmsTemplate) JMSException(javax.jms.JMSException) JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session) Test(org.junit.Test)

Example 27 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project camel by apache.

the class JmsAnotherCustomJMSReplyToTest method testCustomJMSReplyToInOnly.

@Test
public void testCustomJMSReplyToInOnly() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("My name is Arnio");
    // start a inOnly route
    template.sendBody("activemq:queue:hello", "Hello, I'm here");
    // now consume using something that is not Camel
    Thread.sleep(1000);
    JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
    TextMessage msg = (TextMessage) jms.receive("nameRequestor");
    assertEquals("What's your name", msg.getText());
    // there should be a JMSReplyTo so we know where to send the reply
    Destination replyTo = msg.getJMSReplyTo();
    assertEquals("queue://nameReplyQueue", replyTo.toString());
    // send reply
    template.sendBody("activemq:" + replyTo.toString(), "My name is Arnio");
    Thread.sleep(2000);
    assertMockEndpointsSatisfied();
}
Also used : Destination(javax.jms.Destination) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) JmsTemplate(org.springframework.jms.core.JmsTemplate) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 28 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project av-service by dvoraka.

the class JmsServerConfig method fileServerJmsTemplate.

@Bean
public JmsTemplate fileServerJmsTemplate(ConnectionFactory serverConnectionFactory, MessageConverter fileServerMessageConverter) {
    JmsTemplate template = new JmsTemplate(serverConnectionFactory);
    template.setReceiveTimeout(receiveTimeout);
    template.setMessageConverter(fileServerMessageConverter);
    return template;
}
Also used : JmsTemplate(org.springframework.jms.core.JmsTemplate) Bean(org.springframework.context.annotation.Bean)

Example 29 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project av-service by dvoraka.

the class JmsBridgeOutputConfig method outJmsTemplate.

@Bean
public JmsTemplate outJmsTemplate(ConnectionFactory outConnectionFactory, MessageConverter outMessageConverter) {
    JmsTemplate template = new JmsTemplate(outConnectionFactory);
    template.setReceiveTimeout(receiveTimeout);
    template.setMessageConverter(outMessageConverter);
    return template;
}
Also used : JmsTemplate(org.springframework.jms.core.JmsTemplate) Bean(org.springframework.context.annotation.Bean)

Example 30 with JmsTemplate

use of org.springframework.jms.core.JmsTemplate in project opennms by OpenNMS.

the class JmsNorthBounderTest method startBroker.

/**
 * Start broker.
 *
 * @throws InterruptedException the interrupted exception
 */
@Before
public void startBroker() throws InterruptedException {
    MockLogAppender.setupLogging();
    // this spawns an embedded broker
    m_template = new JmsTemplate(m_jmsNorthbounderConnectionFactory);
    m_template.setReceiveTimeout(100L);
}
Also used : JmsTemplate(org.springframework.jms.core.JmsTemplate) Before(org.junit.Before)

Aggregations

JmsTemplate (org.springframework.jms.core.JmsTemplate)46 Test (org.junit.Test)30 ConnectionFactory (javax.jms.ConnectionFactory)12 Session (javax.jms.Session)9 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)8 Connection (javax.jms.Connection)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)7 Bean (org.springframework.context.annotation.Bean)6 Destination (javax.jms.Destination)4 TextMessage (javax.jms.TextMessage)4 CamelContext (org.apache.camel.CamelContext)4 SessionCallback (org.springframework.jms.core.SessionCallback)4 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)4 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)4 JMSException (javax.jms.JMSException)3 Message (javax.jms.Message)3 PooledConnectionFactory (org.apache.activemq.pool.PooledConnectionFactory)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3 JmsOperations (org.springframework.jms.core.JmsOperations)3