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();
}
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();
}
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();
}
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;
}
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);
}
}
Aggregations