4

the title of the question says pretty much all: is it possible to connect to a locally running IBM MQ Light with Java and JMS ? In the comment section of this post, Rob Nicholson says it is not possible, but I wonder if things have changed. Sadly, I was not able to find information that explicitly negate this possibility, apart this comment.

Just to clarify, MQ Light runs locally, not in IBM's bluemix.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
danidemi
  • 4,404
  • 4
  • 34
  • 40

1 Answers1

2

Sure you can use JMS with MQLight!

As MQLight supports the wire protocol AMQP 1.0 you can use, for instance, the Apache QPid Proton library.

Working Sample in two files will produce a message to a MQLight queue.

Main.java

import org.apache.qpid.jms.JmsConnectionFactory;
import javax.jms.*;

public class Main {

    public static void main(String[] args){
        try {
            ConnectionFactory cf = new JmsConnectionFactory("amqp://localhost:5672");
            Connection connection = cf.createConnection();
            Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
            MessageProducer producer = session.createProducer(session.createQueue("QUE.BAR"));
            producer.send(session.createTextMessage("foo bar"));
            producer.close();
            session.close();
            connection.close();
        }catch(JMSException jmsException){
            jmsException.printStackTrace();
        }
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example.test</groupId>
    <artifactId>mqlight-jms</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.qpid</groupId>
            <artifactId>qpid-jms-client</artifactId>
            <version>0.3.0</version>
        </dependency>
    </dependencies>
</project>
Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • Thanks @Petter, just give my colleagues and me the chance to give it a try on the application we're developing and I'll accept your answer. – danidemi Jul 06 '15 at 21:00
  • 1
    How did this work out? I'll also mention that via the beta https://www.ibm.com/developerworks/community/blogs/messaging/entry/update_to_mq_s_beta_support_for_mq_light?lang=en it is possible to use MQ Light API in MQ stand alone now and this will of course interwork with JMS – rob9nicholson Sep 17 '15 at 11:23