use of javax.jms.JMSRuntimeException in project tomee by apache.
the class JMS2AMQTest method cdiListenerAPI.
@Test
public void cdiListenerAPI() throws InterruptedException {
final String text = TEXT + "4";
final AtomicReference<Throwable> error = new AtomicReference<>();
final CountDownLatch ready = new CountDownLatch(1);
final CountDownLatch over = new CountDownLatch(1);
new Thread() {
{
setName(JMS2AMQTest.class.getName() + ".cdiListenerAPI#receiver");
}
@Override
public void run() {
final ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
contextsService.startContext(RequestScoped.class, null);
try {
final JMSConsumer consumer = context.createConsumer(destination3);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(final Message message) {
try {
assertEquals(text, message.getBody(String.class));
} catch (final Throwable e) {
error.set(e);
} finally {
over.countDown();
consumer.close();
}
}
});
ready.countDown();
} catch (final Throwable t) {
error.set(t);
} finally {
try {
over.await(1, TimeUnit.MINUTES);
} catch (final InterruptedException e) {
Thread.interrupted();
}
contextsService.endContext(RequestScoped.class, null);
}
}
}.start();
ready.await(1, TimeUnit.MINUTES);
// now send the message
try (final JMSContext context = cf.createContext()) {
context.createProducer().send(destination3, text);
} catch (final JMSRuntimeException ex) {
fail(ex.getMessage());
}
over.await(1, TimeUnit.MINUTES);
// ensure we got the message and no exception
final Throwable exception = error.get();
if (exception != null) {
exception.printStackTrace();
}
assertNull(exception == null ? "ok" : exception.getMessage(), exception);
}
use of javax.jms.JMSRuntimeException in project tomee by apache.
the class JMS2AMQTest method sendMessageToMdb.
@Test
public void sendMessageToMdb() throws Exception {
try (final JMSContext context = cf.createContext()) {
Message message = context.createMessage();
message.setStringProperty("text", TEXT);
context.createProducer().send(destination, message);
assertTrue(Listener.sync());
} catch (final JMSRuntimeException ex) {
fail(ex.getMessage());
}
}
use of javax.jms.JMSRuntimeException in project tomee by apache.
the class JMS2AMQTest method sendToMdb.
@Test
public void sendToMdb() throws Exception {
try (final JMSContext context = cf.createContext()) {
context.createProducer().send(destination, TEXT);
assertTrue(Listener.sync());
} catch (final JMSRuntimeException ex) {
fail(ex.getMessage());
}
}
use of javax.jms.JMSRuntimeException in project pentaho-kettle by pentaho.
the class JmsStreamSource method receiveLoop.
/**
* Will receive messages from consumer. If timeout is hit, consumer.receive(timeout)
* will return null, and the observable will be completed.
*/
private void receiveLoop() {
Message message;
try {
while (!closed.get() && (message = consumer.receive(receiverTimeout)) != null) {
streamStep.logDebug(message.toString());
Date date = new Date(message.getJMSTimestamp());
DateFormat formatter = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss a");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String jmsTimestamp = formatter.format(date);
acceptRows(singletonList(Arrays.asList(message.getBody(Object.class), jmsDelegate.destinationName, message.getJMSMessageID(), jmsTimestamp, message.getJMSRedelivered())));
}
} catch (JMSRuntimeException | JMSException jmsException) {
error(jmsException);
} finally {
super.close();
if (!closed.get()) {
close();
streamStep.logBasic(getString(PKG, "JmsStreamSource.HitReceiveTimeout"));
}
}
}
use of javax.jms.JMSRuntimeException in project javaee7-samples by javaee-samples.
the class MessageSenderAsync method sendMessage.
/**
* Send a message to the JMS queue. Prin
*
* @param message the contents of the message.
* @throws JMSRuntimeException if an error occurs in accessing the queue.
*/
public void sendMessage(String message) throws JMSRuntimeException {
JMSProducer producer = context.createProducer();
try {
producer.setAsync(new CompletionListener() {
@Override
public void onCompletion(Message msg) {
try {
System.out.println(msg.getBody(String.class));
} catch (JMSException ex) {
Logger.getLogger(MessageSenderAsync.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void onException(Message msg, Exception e) {
try {
System.out.println(msg.getBody(String.class));
} catch (JMSException ex) {
Logger.getLogger(MessageSenderAsync.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
} catch (JMSRuntimeException ex) {
System.out.println("Caught RuntimeException trying to invoke setAsync - not permitted in Java EE. Resorting to synchronous sending...");
}
producer.send(asyncQueue, message);
}
Aggregations