![]() |
Use this task to develop a message bean that a JMS listener invokes when a message arrives on the input queue that the listener is monitoring. You are recommended to develop the message bean to delegate the business processing of incoming messages to another Enterprise JavaBean, to provide clear separation of message handling and business processing. This also enables the business processing to be invoked by either the arrival of incoming messages or, for example, from a WebSphere EJB client. Responses can be handled by another Enterprise JavaBean acting as a sender bean, or handled in the message bean.
You develop a message bean to be invoked by a JMS listener like any other Enterprise JavaBean used by your enterprise applications. To develop a message bean, you complete the following stages:
The message bean class must meet the same requirements as any session bean. It must also define and implement the onMessage() method, which must meet the following requirements:
javax.jms.Message
.For example, a basic onMessage() method for a message bean is shown in the following code extract:
public void onMessage(javax.jms.Message msg) { try { System.out.println("MySessBean.onMessage(), msg text: "+((TextMessage)msg).getText()); } catch (Exception err) { err.printStackTrace(); } }
Code example: The onMessage() method of a message bean. This figure shows a code extract for a basic onMessage() method of a message bean. The method extracts the text from an incoming message and sends that text to System.out.
For more information about writing the message bean class (as a session bean class), see Writing the enterprise bean class (session).
For more information about writing the message bean's home interface, see Writing the home interface (session).
For more information about writing the message bean's remote interface, see Writing the remote interface (session).
When you have developed a message bean to use the extended messaging service, you must package and deploy the bean as part of your enterprise application. For more information about packaging and deploying an enterprise application, see:
Related tasks... | |
Configuring the extended messaging service | |
Related concepts... | |
Parent: An overview of the extended messaging service | |