Basic Send Message to MQ with Java and IBM MQ JMS

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



public class MQSend {
public static void main(String[] args)
try {
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);

MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
//MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection("username","password");
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("queue:///MyTestQueue");

MQQueueSender sender =  (MQQueueSender) session.createSender(queue);

long uniqueNumber = System.currentTimeMillis() % 1000;

TextMessage message = (TextMessage) session.createTextMessage("Basic Queue Test "+ uniqueNumber);    

// Start the connection

System.out.println("Sent message to Queue MyTestQueue: " + message.getText());
System.out.println("Message Sent OK.\n");
catch (JMSException jmsex) {
System.out.println("Message Send Failure\n");
catch (Exception ex) {
System.out.println("Message Send Failure\n");


  1. Thanks for the awesome code.
    Will this code run in java 1.6 ?

    1. Great Article
      Cyber Security Projects

      projects for cse

      Networking Projects

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. Amazing & Great informative blog,it gives very useful practical information to developer like me. Besides that Wisen has established as Best Java Online Training in India . or learn thru Online Training mode Hibernate Online Training . Nowadays Hibernate ORM has tons of job opportunities on various vertical industry. or learn thru JavaScript Online Training in India. Nowadays even JavaScript has tons of job opportunities on various vertical industry.

  3. Hi there I am trying to send messages to MQ queue using Nifi. Nifi uses a processor called PublishJMS to publish messages in the queue. I have been able to do that. But only issue is the JMS is appending message headers and file properties with my message. I only need to send the message on the queue.

  4. Valentine's day, the day of love, which falls on 14th February every year is celebrated by the couple all across the globe. Here is the world famous valentine day website visit here: Happy Valentine’s Day Love

  5. Swagg Sauce, manufacturer of the finest premium vape juice and salt nicotine ingredients crafted with our signature flavor blends and eliquid online. Premium grade vape juice, candy, cream, custard, dessert, fruit, tobacco, menthol and more info click here

  6. thanks for your information really good and very nice web design company in velachery

  7. The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. Machine Learning Final Year Projects In case you will succeed, you have to begin building machine learning projects in the near future.

    Projects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.

    Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.


Post a Comment

Popular posts from this blog

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

MySQL Error Invalid Table or Database Name