The inserted Java code sends a message to the JMS queue listener using the queue connection factory reference and the queue name reference that you provide. You can update the value of the parameter in the setText() method to change the text of the message.
Example snippet insertion for sending a message to a JMS queue listener
public class Main { public void sendMyMessage() { // insert snippet here } }
import com.ibm.etools.service.locator.ServiceLocatorManager; import javax.jms.*; import javax.naming.*; public class Main { private final static String STATIC_CONNECTION_FACTORY_REF_NAME = "queueconnectionfactoryreference"; private final static String STATIC_QUEUE_REF_NAME = "queuename"; public void sendMyMessage() { // insert snippet here send_queuenameMessage(); } protected void send_queuenameMessage() { try { QueueConnectionFactory qConnectionFactory = ServiceLocatorManager .lookupQueueConnectionFactory(STATIC_CONNECTION_FACTORY_REF_NAME); Queue queue = ServiceLocatorManager .lookupQueue(STATIC_QUEUE_REF_NAME); QueueConnection qConnection = qConnectionFactory .createQueueConnection(); QueueSession qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueSender sender = qSession.createSender(queue); TextMessage message = qSession.createTextMessage(); message.setText("Foo Sample Queue message"); sender.send(message); sender.close(); qSession.close(); qConnection.close(); } catch (JMSException jmse) { // TODO Auto-generated catch block jmse.printStackTrace(); } } }
To insert Java code for sending a message to a JMS queue listener:
The ServiceLocatorManager class has a static method called setErrorHandler(ServiceLocatorErrorHandler handler) that you can use to specify a specific error handler for error conditions that occur when looking up the home interface. The default handler simply calls printStackTrace() on the exception that is handled.