Search in sources :

Example 21 with MessageConsumer

use of javax.jms.MessageConsumer in project camel by apache.

the class InOnlyQueueProducerTest method testInOnlyQueueProducer.

@Test
public void testInOnlyQueueProducer() throws Exception {
    MessageConsumer mc = createQueueConsumer(TEST_DESTINATION_NAME);
    assertNotNull(mc);
    final String expectedBody = "Hello World!";
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived(expectedBody);
    template.sendBody("direct:start", expectedBody);
    Message message = mc.receive(5000);
    assertNotNull(message);
    assertTrue(message instanceof TextMessage);
    TextMessage tm = (TextMessage) message;
    String text = tm.getText();
    assertNotNull(text);
    template.sendBody("direct:finish", text);
    mock.assertIsSatisfied();
    mc.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 22 with MessageConsumer

use of javax.jms.MessageConsumer in project camel by apache.

the class InOnlyTopicProducerTest method testInOnlyTopicProducerProducer.

@Test
public void testInOnlyTopicProducerProducer() throws Exception {
    MessageConsumer mc = createTopicConsumer(TEST_DESTINATION_NAME, null);
    assertNotNull(mc);
    final String expectedBody = "Hello World!";
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived(expectedBody);
    template.sendBody("direct:start", expectedBody);
    Message message = mc.receive(5000);
    assertNotNull(message);
    assertTrue(message instanceof TextMessage);
    TextMessage tm = (TextMessage) message;
    String text = tm.getText();
    assertNotNull(text);
    template.sendBody("direct:finish", text);
    mock.assertIsSatisfied();
    mc.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 23 with MessageConsumer

use of javax.jms.MessageConsumer in project camel by apache.

the class InOnlyQueueProducerTest method testInOnlyQueueProducer.

@Test
public void testInOnlyQueueProducer() throws Exception {
    MessageConsumer mc = createQueueConsumer(TEST_DESTINATION_NAME);
    assertNotNull(mc);
    final String expectedBody = "Hello World!";
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived(expectedBody);
    template.sendBody("direct:start", expectedBody);
    Message message = mc.receive(5000);
    assertNotNull(message);
    assertTrue(message instanceof TextMessage);
    TextMessage tm = (TextMessage) message;
    String text = tm.getText();
    assertNotNull(text);
    template.sendBody("direct:finish", text);
    mock.assertIsSatisfied();
    mc.close();
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 24 with MessageConsumer

use of javax.jms.MessageConsumer in project camel by apache.

the class SjmsConsumer method createConsumer.

/**
     * Creates a {@link MessageConsumerResources} with a dedicated
     * {@link Session} required for transacted and InOut consumers.
     */
private MessageConsumerResources createConsumer() throws Exception {
    MessageConsumerResources answer;
    ConnectionResource connectionResource = getOrCreateConnectionResource();
    Connection conn = connectionResource.borrowConnection();
    try {
        Session session = conn.createSession(isTransacted(), isTransacted() ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE);
        MessageConsumer messageConsumer = getEndpoint().getJmsObjectFactory().createMessageConsumer(session, getEndpoint());
        MessageListener handler = createMessageHandler(session);
        messageConsumer.setMessageListener(handler);
        answer = new MessageConsumerResources(session, messageConsumer);
    } catch (Exception e) {
        log.error("Unable to create the MessageConsumer", e);
        throw e;
    } finally {
        connectionResource.returnConnection(conn);
    }
    return answer;
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ConnectionResource(org.apache.camel.component.sjms.jms.ConnectionResource) Connection(javax.jms.Connection) MessageListener(javax.jms.MessageListener) Session(javax.jms.Session)

Example 25 with MessageConsumer

use of javax.jms.MessageConsumer in project gocd by gocd.

the class JMSMessageListenerAdapterTest method shouldNotKillTheThreadWhenThereIsAnException.

@Test
public void shouldNotKillTheThreadWhenThereIsAnException() throws Exception {
    MessageConsumer consumer = mock(MessageConsumer.class);
    when(consumer.receive()).thenThrow(new RuntimeException("should swallow me"));
    GoMessageListener mockListener = new GoMessageListener() {

        public void onMessage(GoMessage message) {
            throw new UnsupportedOperationException("not implemented yet");
        }

        @Override
        public String toString() {
            return "test-listener";
        }
    };
    JMSMessageListenerAdapter listenerAdapter = JMSMessageListenerAdapter.startListening(consumer, mockListener, mock(DaemonThreadStatsCollector.class));
    try {
        listenerAdapter.runImpl();
    } catch (Exception e) {
        e.printStackTrace();
        fail("expected no exception get: " + e);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) DaemonThreadStatsCollector(com.thoughtworks.go.server.service.support.DaemonThreadStatsCollector) GoMessageListener(com.thoughtworks.go.server.messaging.GoMessageListener) GoMessage(com.thoughtworks.go.server.messaging.GoMessage) Test(org.junit.Test)

Aggregations

MessageConsumer (javax.jms.MessageConsumer)82 Session (javax.jms.Session)53 Message (javax.jms.Message)40 MessageProducer (javax.jms.MessageProducer)40 Test (org.junit.Test)39 Connection (javax.jms.Connection)38 TextMessage (javax.jms.TextMessage)38 ConnectionFactory (javax.jms.ConnectionFactory)14 JMSException (javax.jms.JMSException)14 Destination (javax.jms.Destination)12 Queue (javax.jms.Queue)8 TemporaryQueue (javax.jms.TemporaryQueue)8 ObjectMessage (javax.jms.ObjectMessage)6 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 Serializable (java.io.Serializable)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 MessageListener (javax.jms.MessageListener)4 HornetQMixIn (org.switchyard.component.test.mixins.hornetq.HornetQMixIn)4 ArrayList (java.util.ArrayList)3