1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| public class JmsLogReceiverTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
}
public void testJms() throws NamingException{
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "UrlDeMonServeur");
Context ctx = new InitialContext(props);
TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) ctx.lookup("NomDeMaConnectionFactory");
TopicConnection topicConnection = null;
Topic myTopic = (Topic) ctx.lookup("NomDeMonTopic");
try {
topicConnection = topicConnectionFactory.createTopicConnection();
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber topicSubscriber = topicSession.createSubscriber(myTopic);
MessageListener topicListener = new MessageListener(){
public void onMessage(Message arg0) {
ObjectMessage message = (ObjectMessage) arg0;
try {
#
#
#
#
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
topicSubscriber.setMessageListener(topicListener);
topicConnection.start();
boolean again = true;
while(again){
again = true;
}
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if (topicConnection!=null){
try {
topicConnection.close();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
} |
Partager