List of usage examples for javax.jms CompletionListener CompletionListener
CompletionListener
From source file:org.sample.send.receive.MessageSenderAsync.java
public void sendMessage(String message) { try {// ww w .ja v a2s. c om context.createProducer().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 (RuntimeException e) { System.out.println("Caught RuntimeException trying to invoke setAsync - not permitted in Java EE"); } context.createProducer().send(syncQueue, message); context.createProducer().send(asyncQueue, message); }