0

I want to read multiple messages from IBM MQ asynchronously . I am just using MessageDrivenBean configurations like below.

import java.io.IOException;
import java.util.ArrayList;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.Asynchronous;
import javax.ejb.EJBException;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.ejb.Stateless;
import javax.jms.*;


import com.tlr.searchextract.messages.MessageHandler;

@MessageDriven(
           name = "MessageTrigger_ABean",
           activationConfig = {
              @ActivationConfigProperty( propertyName = "destinationType", 
                                         propertyValue = "javax.jms.Queue"),
              @ActivationConfigProperty( propertyName = "destination", 
                                         propertyValue ="COMSERV.SRCHEXT.EVENTS.PUBLISH.QA.Q01"),
              @ActivationConfigProperty( propertyName = "hostname", 
              propertyValue ="reese"),
              @ActivationConfigProperty( propertyName = "channel", 
              propertyValue ="CLIENTCONNECTION"),
              @ActivationConfigProperty( propertyName = "port", 
              propertyValue ="1414")
           }
        )
/**
 * Bean implementation class for Enterprise Bean: MessageTrigger_A
 */

public class MessageTrigger_ABean implements MessageListener,MessageDrivenBean
     {
  /**
     * 
     */
    //private static final long serialVersionUID = 1L;
    private MessageDrivenContext fMessageDrivenCtx;
    
    
public javax.ejb.MessageDrivenContext getMessageDrivenContext() {
        return fMessageDrivenCtx;
    }
@Override
public void ejbRemove() throws EJBException {
    // TODO Auto-generated method stub
    
}

@Override
public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException {
    fMessageDrivenCtx = ctx;
    
}


/**
 * onMessage
 */
public void onMessage(Message msg) {
    
    String messageText = "";
     System.out.println("inside onMessage of MessageTrigger_ABean ");
    try {
      System.out.println("check if msg instance of bytes");
        if (msg instanceof BytesMessage) {

            int length;
            byte[] buf2 = new byte[100];
            StringBuffer sb = new StringBuffer();
            BytesMessage bytesMessage = ((BytesMessage) msg);
            do {
                length = bytesMessage.readBytes(buf2);
                if (length != -1) {
                    for (int i = 0; i < length; i++) {
                        //System.out.print((char) buf2[i]);
                        sb.append((char) buf2[i]);
                    }
                }
            }
            while (length >= 100);
            messageText = sb.toString();

        }
        
        else if (msg instanceof TextMessage) {
            System.out.println("check if msg instance of text");
            messageText = ((TextMessage) msg).getText();
        }

        int angleLeft = 0;
        angleLeft = messageText.indexOf("<");
        messageText = messageText.substring(angleLeft, messageText.length());
        
        MessageHandler mh = new MessageHandler();
        System.out.println("messagehandler java file:"+messageText);
        mh.processMessages(messageText);

    }
    catch (Exception e) {
        System.out.println("JMSException: " + e.getMessage());
        
    }
    
}
    
}

Here onMessage method is not getting called even though the messages are present in the queue. Please tell me where I am doing wrong. I am using below ejb jar and I dont have any configurations in ejb-jar.xml since I am using annotations here. javax.ejb-api-3.2.jar

C2D
  • 29
  • 1
  • 6
  • Are you using a resource adapter for W-MQ? It's kind of unusual to see a hostname and port in an activation spec -- usually that's configured in the resource adapter setup. And do you really have a queue called `queuename` ? What appserver is this? – Kevin Boone Sep 18 '20 at 11:44
  • this is actually a Tomcat application. where can i configure hostname and port ? and queuename is different. i will edit in the question – C2D Sep 18 '20 at 12:12
  • Sorry -- this is beyond me. I didn't even that Tomcat supported MDBs. I know that IBM issues a JCA-compliant resource adapter that can be installed in many application servers, although the installation procedures vary between products. Typically you'd configure the connection properties in the application server's own configuration, and just expose it to applications as a JNDI name. Sorry -- good luck. – Kevin Boone Sep 18 '20 at 12:21

0 Answers0