Java Send / Read from Remote MQ Queue on CentOS Linux

package my.mq.samples;

import javax.jms.JMSException;
import javax.jms.Session;

import com.ibm.jms.JMSMessage;
import com.ibm.jms.JMSTextMessage;

import com.ibm.mq.jms.MQQueue;


import com.ibm.mq.jms.MQQueueConnection;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.mq.jms.MQQueueReceiver;
import com.ibm.mq.jms.MQQueueSender;
import com.ibm.mq.jms.MQQueueSession;
import com.ibm.msg.client.jms.*;
import com.ibm.msg.client.services.*;
import com.ibm.msg.client.wmq.WMQConstants;

public class MQConnect {

   
public static void main(String[] args) {

    try {
      MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
      cf.setHostName("82.195.136.246");
      cf.setPort(60000);
     
      cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
     
      cf.setQueueManager("dtm.queue.manager");
      cf.setChannel("SYSTEM.DEF.SVRCONN");
     
      MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection("Trevor","Password");
     
      MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      MQQueue queue = (MQQueue) session.createQueue("queue:///Q1");
      MQQueueSender sender =  (MQQueueSender) session.createSender(queue);
      MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(queue);    
     
      long uniqueNumber = System.currentTimeMillis() % 1000;
      JMSTextMessage message = (JMSTextMessage) session.createTextMessage("Basic Queue Test "+ uniqueNumber);    

      // Start the connection
      connection.start();
      sender.send(message);
      System.out.println("Sent message:\\n" + message);
      JMSMessage receivedMessage = (JMSMessage) receiver.receive(10000);
      System.out.println("\\nReceived message:\\n" + receivedMessage);
      sender.close();
      receiver.close();
      session.close();
      connection.close();
      System.out.println("\\nSUCCESS\\n");
    }
    catch (JMSException jmsex) {
      System.out.println(jmsex);
      System.out.println("\\nFAILURE\\n");
    }
    catch (Exception ex) {
      System.out.println(ex);
      System.out.println("\\nFAILURE\\n");
    }
  }
}

Comments

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete
  2. Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post. UP Ration Card application

    ReplyDelete
  3. am not able to receive message from the above code. am always getting null response.
    Try to receive the message from the MQ. I can able to see the messages in the MQ Explorer. But i cant able to get the messages. It always return null. But i can able to drop message to the Queue.

    ReplyDelete

  4. Very useful information to everyone thanks for sharing, learn the latest updated Technology at Best Training institutions
    Salesforce Lightning is the latest updated technology
    Salesforce Online Training in Bangalore
    Salesforce Training online in India

    ReplyDelete
  5. com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ1017: non-local MQ queue 'VOLSWITCH_MQ1.REQUEST.FROM.TCH_MQ1' not valid for receiving or browsing.
    The MQ queue is not able to be opened, as it is not local to the connected Queue Manager.
    Connect to the Queue Manager for which this MQ Queue resides locally.
    \nFAILURE\n


    As I am working on Remote queue...I want to put message on remote queue

    ReplyDelete
  6. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
    Salesforce certification training

    ReplyDelete
  7. Nice content very helpful, It has a very important point which should be noted down. All points were mentions and very well written. Keep Posting & writing such content.


    Online AWS Certification Training
    online aws Course

    ReplyDelete

Post a Comment

Popular posts from this blog

ActiveMQ, easy to use open source message oriented middleware (MOM)

Basic Send Message to MQ with Java and IBM MQ JMS

MySQL Error Invalid Table or Database Name