Jakarta ee 将同一Mdb java类关联到Ejb3 jboss 5.x服务器中的多个队列

Jakarta ee 将同一Mdb java类关联到Ejb3 jboss 5.x服务器中的多个队列,jakarta-ee,jms,jboss5.x,Jakarta Ee,Jms,Jboss5.x,上面的代码是我的消息驱动bean,对于单个队列“Queue1”来说工作得很好。现在我想将Queue2关联到同一个mdb。 我可以通过创建另一个mdb类“EJB3MessageDrivenBean2”和如下更改activationConfig属性来做同样的事情 package jboss5.ejb3.mdb; import java.util.HashMap; import javax.ejb.ActivationConfigProperty; import javax.ejb.EJB; im

上面的代码是我的消息驱动bean,对于单个队列“Queue1”来说工作得很好。现在我想将Queue2关联到同一个mdb。 我可以通过创建另一个mdb类“EJB3MessageDrivenBean2”和如下更改activationConfig属性来做同样的事情

 package jboss5.ejb3.mdb;

import java.util.HashMap;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.naming.InitialContext;

@MessageDriven(
    activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName="destination", propertyValue="queue/Queue1"),
    }
    )

@TransactionManagement(TransactionManagementType.CONTAINER)
@EJB(name = "EJB3MessageDrivenLocal1", beanInterface = EJB3MessageDrivenLocal.class)

 public class EJB3MessageDrivenBean implements MessageDrivenBean, MessageListener
 {
ObjectMessage msg = null;
private MessageDrivenContext mdc = null;

public EJB3MessageDrivenBean() {}

public void setMessageDrivenContext(MessageDrivenContext mdc) {
    this.mdc = mdc;
}

public void onMessage(Message inMessage) {
        }

@Override
public void ejbRemove() throws EJBException {
    // TODO Auto-generated method stub
}
 }
但在这种方法中,我必须复制我的代码,将来如果我必须关联另一个队列Queue3,那么我必须再次复制java文件

通过更改xml文件中的任何其他方法或任何其他方法

更多细节

假设队列1中的消息是JmsMsg11、JmsMsg12、JmsMsg13、JmsMsg14 假设队列2中的消息是JmsMsg21、JmsMsg22、JmsMsg23、JmsMsg24

我必须同时处理JmsMsg11和JmsMsg21。在处理完JmsMsg11之后,我必须先处理JmsMsg12,然后是JmsMsg13,然后是JmsMsg14。同样的情况也适用于queue2

我在WebLogic10.x中也做了同样的事情,通过以下代码对ejb-jar.xml和weblogic-ejb-jar.xml进行了一些更改。不知道在JBoss5.x中该怎么做。 ejb-jar.xml

    @MessageDriven(
    activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName="destination", propertyValue="queue/Queue2"),
    }
    )
    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    <enterprise-beans>
    <message-driven>
      <ejb-name>WeblogicEjb3MDB1</ejb-name>
      <ejb-class>jboss5.ejb3.mdb.EJB3MessageDrivenBean</ejb-class>
      <messaging-type>javax.jms.MessageListener</messaging-type>
  <transaction-type>Container</transaction-type>

<activation-config>
    <activation-config-property>
        <activation-config-property-name>
            DestinationType
        </activation-config-property-name>
        <activation-config-property-value>
            javax.jms.Queue
        </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
        <activation-config-property-name>
            DestinationJndiName
        </activation-config-property-name>
        <activation-config-property-value>
           Queue1
        </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
        <activation-config-property-name>
            ConnectionFactoryJndiName
        </activation-config-property-name>
        <activation-config-property-value>
            QFact1
        </activation-config-property-value>
    </activation-config-property>
   </activation-config>
 </message-driven>
     <message-driven>
       <ejb-name>WeblogicEjb3MDB2</ejb-name>
       <ejb-class>jboss5.ejb3.mdb.EJB3MessageDrivenBean</ejb-class>
       <messaging-type>javax.jms.MessageListener</messaging-type>
       <transaction-type>Container</transaction-type>

   <activation-config>
    <activation-config-property>
        <activation-config-property-name>
            DestinationType
        </activation-config-property-name>
        <activation-config-property-value>
            javax.jms.Queue
        </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
        <activation-config-property-name>
            DestinationJndiName
        </activation-config-property-name>
        <activation-config-property-value>
           Queue2
        </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
        <activation-config-property-name>
            ConnectionFactoryJndiName
        </activation-config-property-name> 
        <activation-config-property-value>
            QFact2
        </activation-config-property-value>
    </activation-config-property>
     </activation-config>
   </message-driven>
 </enterprise-beans>

   <assembly-descriptor>
        <container-transaction>
          <method>
             <ejb-name>WeblogicEjb3MDB1</ejb-name>
             <method-name>onMessage</method-name>
         </method>
  <trans-attribute>NotSupported</trans-attribute>
</container-transaction>

<container-transaction>
  <method>
    <ejb-name>WeblogicEjb3MDB2</ejb-name>
    <method-name>onMessage</method-name>
  </method>
  <trans-attribute>NotSupported</trans-attribute>
</container-transaction>

WeblogicEjb3MDB1
jboss5.ejb3.mdb.EJB3MessageDrivenBean
javax.jms.MessageListener
容器
目的型
javax.jms.Queue
目的地名称
队列1
ConnectionFactoryJndiName
QFact1
WeblogicEjb3MDB2
jboss5.ejb3.mdb.EJB3MessageDrivenBean
javax.jms.MessageListener
容器
目的型
javax.jms.Queue
目的地名称
队列2
ConnectionFactoryJndiName
QFact2
WeblogicEjb3MDB1
onMessage
不支持
WeblogicEjb3MDB2
onMessage
不支持

weblogic-ejb-jar.xml

    @MessageDriven(
    activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName="destination", propertyValue="queue/Queue2"),
    }
    )
    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    <enterprise-beans>
    <message-driven>
      <ejb-name>WeblogicEjb3MDB1</ejb-name>
      <ejb-class>jboss5.ejb3.mdb.EJB3MessageDrivenBean</ejb-class>
      <messaging-type>javax.jms.MessageListener</messaging-type>
  <transaction-type>Container</transaction-type>

<activation-config>
    <activation-config-property>
        <activation-config-property-name>
            DestinationType
        </activation-config-property-name>
        <activation-config-property-value>
            javax.jms.Queue
        </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
        <activation-config-property-name>
            DestinationJndiName
        </activation-config-property-name>
        <activation-config-property-value>
           Queue1
        </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
        <activation-config-property-name>
            ConnectionFactoryJndiName
        </activation-config-property-name>
        <activation-config-property-value>
            QFact1
        </activation-config-property-value>
    </activation-config-property>
   </activation-config>
 </message-driven>
     <message-driven>
       <ejb-name>WeblogicEjb3MDB2</ejb-name>
       <ejb-class>jboss5.ejb3.mdb.EJB3MessageDrivenBean</ejb-class>
       <messaging-type>javax.jms.MessageListener</messaging-type>
       <transaction-type>Container</transaction-type>

   <activation-config>
    <activation-config-property>
        <activation-config-property-name>
            DestinationType
        </activation-config-property-name>
        <activation-config-property-value>
            javax.jms.Queue
        </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
        <activation-config-property-name>
            DestinationJndiName
        </activation-config-property-name>
        <activation-config-property-value>
           Queue2
        </activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
        <activation-config-property-name>
            ConnectionFactoryJndiName
        </activation-config-property-name> 
        <activation-config-property-value>
            QFact2
        </activation-config-property-value>
    </activation-config-property>
     </activation-config>
   </message-driven>
 </enterprise-beans>

   <assembly-descriptor>
        <container-transaction>
          <method>
             <ejb-name>WeblogicEjb3MDB1</ejb-name>
             <method-name>onMessage</method-name>
         </method>
  <trans-attribute>NotSupported</trans-attribute>
</container-transaction>

<container-transaction>
  <method>
    <ejb-name>WeblogicEjb3MDB2</ejb-name>
    <method-name>onMessage</method-name>
  </method>
  <trans-attribute>NotSupported</trans-attribute>
</container-transaction>

WeblogicEjb3MDB1
1.
队列1
600
WeblogicEjb3MDB2
1.
队列2
600