package queue.app;
import javax.annotation.PostConstruct;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.ibm.mq.jms.MQQueue;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.msg.client.wmq.WMQConstants;
@Component
public class QueueConsumer implements MessageListener{
private Logger logger = Logger.getLogger(getClass());
MQQueueConnectionFactory qcf = new MQQueueConnectionFactory();
QueueConnection qc;
Queue queue;
QueueSession queueSession;
QueueReceiver qr;
@Value("${jms.hostName}")
String jmsHost;
@Value("${jms.port}")
String jmsPort;
@Value("${jms.queue.name}")
String QUEUE_NAME;
@Value("${jms.queueManager}")
String jmsQueueMgr;
@Value("${jms.username}")
String jmsUserName;
@Value("${jms.channel}")
String jmsChannel;
@PostConstruct
public void init() throws Exception{
qcf.setHostName (jmsHost);
qcf.setPort (Integer.parseInt(jmsPort));
qcf.setQueueManager (jmsQueueMgr);
qcf.setChannel (jmsChannel);
qcf.setTransportType (WMQConstants.WMQ_CM_CLIENT);
qc = qcf.createQueueConnection ();
queue = new MQQueue(QUEUE_NAME);
qc.createQueueSession (false, Session.AUTO_ACKNOWLEDGE);
queueSession = qc.createQueueSession (false, Session.AUTO_ACKNOWLEDGE);
qr = queueSession.createReceiver(queue);
qr.setMessageListener(this);
qc.start();
}
@Override
public void onMessage(Message message) {
logger.info("Inside On Message...");
long t1 = System.currentTimeMillis();
logger.info("Message consumed at ...."+t1);
try{
if(message instanceof TextMessage) {
logger.info("String message recieved )) "+((TextMessage) message).getText());
}
}catch(Exception e){
e.printStackTrace();
}
}
}
(dependency)
(groupId)com.sun.messaging.mq(/groupId)
(artifactId)fscontext(/artifactId)
(version)4.2(/version)
(scope)test(/scope)
(/dependency)
(dependency)
(groupId)com.ibm(/groupId)
(artifactId)jms(/artifactId)
(version)1.0(/version)
(/dependency)
(dependency)
(groupId)org.springframework(/groupId)
(artifactId)spring-jms(/artifactId)
(version)3.2.17.RELEASE(/version)
(/dependency)
(dependency)
(groupId)com.ibm(/groupId)
(artifactId)com.ibm.mq(/artifactId)
(version)1.0(/version)
(/dependency)
(dependency)
(groupId)com.ibm(/groupId)
(artifactId)com.ibm.mq.allclient(/artifactId)
(version)1.0(/version)
(/dependency)
(dependency)
(groupId)com.ibm(/groupId)
(artifactId)com.ibm.mq.jmqi(/artifactId)
(version)1.0(/version)
(/dependency)
(dependency)
(groupId)com.ibm(/groupId)
(artifactId)com.ibm.mqjms(/artifactId)
(version)1.0(/version)
(/dependency)
No comments:
Post a Comment