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