use of javax.jms.MessageConsumer in project tomee by apache.
the class Messages method receiveMessage.
public String receiveMessage() throws JMSException {
Connection connection = null;
Session session = null;
MessageConsumer consumer = null;
try {
connection = connectionFactory.createConnection();
connection.start();
// Create a Session
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a MessageConsumer from the Session to the Topic or Queue
consumer = session.createConsumer(chatQueue);
// Wait for a message
TextMessage message = (TextMessage) consumer.receive(1000);
return message.getText();
} finally {
if (consumer != null) {
consumer.close();
}
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
}
use of javax.jms.MessageConsumer in project tomee by apache.
the class ChatBeanTest method test.
public void test() throws Exception {
EJBContainer.createEJBContainer().getContext().bind("inject", this);
final Connection connection = connectionFactory.createConnection();
connection.start();
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageProducer questions = session.createProducer(questionQueue);
final MessageConsumer answers = session.createConsumer(answerQueue);
sendText("Hello World!", questions, session);
assertEquals("Hello, Test Case!", receiveText(answers));
sendText("How are you?", questions, session);
assertEquals("I'm doing well.", receiveText(answers));
sendText("Still spinning?", questions, session);
assertEquals("Once every day, as usual.", receiveText(answers));
}
use of javax.jms.MessageConsumer in project gocd by gocd.
the class ActiveMqMessagingService method addListener.
public JMSMessageListenerAdapter addListener(String topic, final GoMessageListener listener) {
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createTopic(topic));
return JMSMessageListenerAdapter.startListening(consumer, listener, daemonThreadStatsCollector);
} catch (Exception e) {
throw bomb(e);
}
}
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);
}
}
use of javax.jms.MessageConsumer in project cxf by apache.
the class JAXRSJmsTest method checkBookInResponse.
private void checkBookInResponse(Session session, Destination replyToDestination, long bookId, String bookName) throws Exception {
MessageConsumer consumer = session.createConsumer(replyToDestination);
BytesMessage jmsMessage = (BytesMessage) consumer.receive(5000);
if (jmsMessage == null) {
throw new RuntimeException("No response recieved on " + replyToDestination);
}
byte[] bytes = new byte[(int) jmsMessage.getBodyLength()];
jmsMessage.readBytes(bytes);
InputStream is = new ByteArrayInputStream(bytes);
Book b = readBook(is);
assertEquals(bookId, b.getId());
assertEquals(bookName, b.getName());
}
Aggregations