Creating a MessageProducer object to send Messages.

Enterprise Java
Guarantee Inter-Enterprise Message Delivery Using JMS
Gopalan Suresh Raj
Listing 3. Creating a MessageProducer object to send Messages.


// Create a publisher (MessageProducer) for this topic
TopicPublisher topicPublisher = topicSession.createPublisher (topic);

// Create a Map Message for use in the while loop
MapMessage mapMsg = topicSession.createMapMessage ();

// Publish Stock Quotes
// Set and Publish the message
mapMsg.setDouble ("SUNW", 100);
mapMsg.setDouble ("MSFT", 99);
mapMsg.setDouble ("CPWR", 98);
topicPublisher.publish (mapMsg);