1 23 package mail; 24 25 import javax.jms.*; 26 27 30 public class MsgListener implements MessageListener { 31 String ident = null; 32 33 public MsgListener() {} 34 35 public MsgListener(String ident) { 36 this.ident = ident; 37 } 38 39 public void onMessage(Message msg) { 40 try { 41 if (ident != null) System.out.println(ident); 42 43 if (msg instanceof TextMessage) { 44 System.out.println(((TextMessage) msg).getText()); 45 } else if (msg instanceof ObjectMessage) { 46 System.out.println(((ObjectMessage) msg).getObject()); 47 } 48 } catch (JMSException jE) { 49 System.err.println("Exception in listener: " + jE); 50 } 51 } 52 } 53 | Popular Tags |