📄 mdbexample.java
字号:
package org.artemis.right.ejb;
import javax.ejb.EJBException;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
/**
* XDoclet-based Message Driven entity bean.
*
* To generate EJB related classes using XDoclet:
*
* - Add Standard EJB module to XDoclet project properties
* - Customize XDoclet configuration
* - Run XDoclet
*
* Below are the xdoclet-related tags needed for this EJB.
*
* @ejb.bean name="MDBExample"
* display-name="Name for MDBExample11"
* description="Description for MDBExample"
* destination-type="javax.jms.Queue"
* jndi-name="jms/MDBExample"
* acknowledge-mode="Auto-acknowledge"
*
*@ejb.message-driven
* destination-jndi-name="="SendJMSQueue"
* initial-context-factory="weblogic.jndi.WLInitialContextFactory"
* connection-factory-jndi-name="SendJMSFactory"
*
*/
public class MDBExample implements MessageDrivenBean, MessageListener {
/** The MessageDrivenContext */
private MessageDrivenContext context;
public MDBExample() {
super();
// TODO Auto-generated constructor stub
}
/**
* Set the associated context. The container calls this method
* after the instance creation. <br>
*
* The enterprise bean instance should store the reference to the context
* object in an instance variable. <br>
*
* This method is called with no transaction context.
*
* @param newContext A MessageDrivenContext interface for the instance.
*
* @throws EJBException Thrown by the method to indicate a failure caused by a system-level error.
*/
public void setMessageDrivenContext(MessageDrivenContext newContext)
throws EJBException {
context = newContext;
}
public void ejbRemove() throws EJBException {
// TODO Auto-generated method stub
}
public void onMessage(Message arg0) {
// TODO Auto-generated method stub
try {
String msgText;
if (arg0 instanceof TextMessage) {
msgText = ((TextMessage)arg0).getText();
System.out.println("JMSMessageID = "+arg0.getJMSMessageID());
System.out.println("JMSRedelivered = "+arg0.getJMSRedelivered());
System.out.println("JMSCorrelationID = "+arg0.getJMSCorrelationID());
System.out.println("JMSDeliveryMode = "+arg0.getJMSDeliveryMode());
System.out.println("JMSPriority = "+arg0.getJMSPriority());
System.out.println("JMSReplyTo = "+arg0.getJMSReplyTo());
} else {
msgText = arg0.toString();
}
System.out.println("mdbMessage Received: "+ msgText );
} catch (JMSException jmse) {
jmse.printStackTrace();
}
}
/**
* An ejbCreate method as required by the EJB specification.
*
* The container calls the instance?s <code>ejbCreate</code> method
* immediately after instantiation.
*
* @ejb.create-method
*/
public void ejbCreate() {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -