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