Discussions

EJB design: Associate Same Mdb java to multiple queue in Ejb3 jboss 5.x serve

  1. 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
        }
    }

     

     

    Above code is my message driven bean and working fine for single queue 'Queue1'. Now i want to associate Queue2 to same mdb.
    I can do the same thing by creating another mdb class "EJB3MessageDrivenBean2" and by just changing activationConfig property as follow.

     

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

     

     


    but in this method i have to replicate my code and in future if i have to associate another queue Queue3 then i have to again replicate java file.

    Any other method by changing in xml file or any other method.

  2. Can we have more than one[ Go to top ]

    Can we have more than one MDB bind to a single queue? How to ensure each MDB consumes its intended messag? - Texas Lending