Java Reference
In-Depth Information
C
publishMessages(msg,msg2);
}
else
{
System.out.println("This message is not handled" +
" by this MBean");
return;
}
}
catch(Exception ex)
{
System.err.println("Could not handle message: " + ex);
ex.printStackTrace();
}
}
public void publishMessages(String msg,String msg2)
{
Topic topic=null;
TopicPublisher topicPublisher=null;
TopicSession sendTopicSession=null;
TextMessage message=null;
Post
messages
D
try
{
System.out.println("Will publish "+msg
+" Message to Device topic");
// Look up the destination
topic = (Topic)context.lookup("/topic/deviceMessages");
System.out.println("Found the deviceMessages Topic");
// Create a publisher
sendTopicSession = topicConnection.createTopicSession(
false, Session.AUTO_ACKNOWLEDGE);
topicPublisher = sendTopicSession.createPublisher(topic);
// Create a message
message = sendTopicSession.createTextMessage();
message.setText(msg);
// Publish the message
topicPublisher.publish(topic, message);
System.out.println("Published "+msg
+" to deviceMessages Topic");
// Create a message
message = sendTopicSession.createTextMessage();
message.setText(msg2);
// Publish the message
topicPublisher.publish(topic, message);
System.out.println("Published "+msg2
+" to deviceMessages Topic");
}
Search WWH ::




Custom Search