简体   繁体   English

是否可以使用Java和JMS连接到本地运行的IBM MQ Light?

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

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 ? 问题的标题几乎全部说明:是否可以使用Java和JMS连接到本地运行的IBM MQ Light? In the comment section of this post , Rob Nicholson says it is not possible, but I wonder if things have changed. 这篇文章的评论部分,Rob Nicholson说这是不可能的,但我想知道事情是否已经改变。 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. 为了澄清,MQ Light在本地运行,而不是在IBM的bluemix中运行。

Sure you can use JMS with MQLight! 当然你可以在MQLight中使用JMS!

As MQLight supports the wire protocol AMQP 1.0 you can use, for instance, the Apache QPid Proton library . 由于MQLight支持有线协议AMQP 1.0,因此您可以使用Apache QPid Proton库

Working Sample in two files will produce a message to a MQLight queue. 两个文件中的Working Sample将生成一条到MQLight队列的消息。

Main.java 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 的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM