Is it possible to connect to a locally running IBM MQ Light with Java and JMS?

the title of the question says almost everything: is it possible to connect to a locally running IBM MQ Light with Java and JMS? In the comments section of this post, Rob Nicholson says this is not possible, but I wonder if everyone has changed. Unfortunately, I could not find information that clearly denies this possibility, other than this comment.

Just to clarify, MQ Light works locally, not on IBM bluemix.

+4
source share
1 answer

Of course you can use JMS with MQLight!

MQLight AMQP 1.0, , , Apache QPid Proton library.

MQLight.

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>
+2

All Articles