【问题标题】:How to write a sender application for ActiveMQ in Node JS如何在 Node JS 中为 ActiveMQ 编写发送方应用程序
【发布时间】:2015-04-19 00:47:56
【问题描述】:

我想创建一个用于消息传递的 JMS 发送应用程序,并使用 JAVA 创建了相同的应用程序。这是我的 Java 示例代码 sn-p。

    try {
        factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
        connection = factory.createConnection();
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        destination = session.createQueue("SAMPLEQUEUE");
        producer = session.createProducer(destination);
        try {

                TextMessage message = session.createTextMessage();
                message.setText("hello");
                producer.send(message);
                System.out.println("Sent: " + message.getText());

        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (JMSException e) {
        e.printStackTrace();
    }

这很好用,我也可以用我的接收器接收消息。我想更改 Node JS 中的发送者实现并使其成为 Node JS 应用程序。在 Node JS 中搜索 ActiveMQ 后,我对 Node JS 并不了解。任何指向它的指针都会很有帮助。

问候, 苏汉卡

编辑

我在节点 JS 中使用了 stomp。示例代码如下:

var Stomp = require('stomp-client');
var destination = '/queue/sensorstreamqueue';
var client = new Stomp('10.53.219.153', 61613, 'user', 'pass');
var     lazy    = require("lazy"),
        fs  = require("fs");



client.connect(function(sessionId) {
new lazy(fs.createReadStream('input.csv'))
     .lines
     .forEach(function(line){
         client.publish(destination, line.toString());
     }
 );   
    console.log("published");
});

代码有效,我的接收者也收到了消息,但是我的接收者认为它是 textMesssage 格式并给出以下错误:

02-19-2015 08:42:31.288 ERROR [Thread-25] (JmsInputTransporter.handleTextMessage) Error code:401306, Severity : 3 (Error)
Error message:JMS Transporter is expected a TextMessage, received class org.apache.activemq.command.ActiveMQBytesMessage.
Error description:JMS Transporter is expected a TextMessage, received class org.apache.activemq.command.ActiveMQBytesMessage.

有人可以帮助我如何实现这一目标吗?

【问题讨论】:

  • 你能附上你的接收者代码吗?
  • 嗨 Josh,很遗憾,接收方是我不拥有的组件的一部分,并且希望消息采用文本消息格式
  • 对于投了反对票的人,如果你能解释一下你不喜欢这个问题的地方,那就太好了。或许我下次可以改进!!
  • 我注意到我正在处理的类似问题。通过 stomp-client 发送消息最终在 Java 应用程序中作为 content 属性中的 ByteSequence,但在 text 属性中应该是纯文本。如果我发现了什么,我会回来查看。

标签: java node.js activemq stomp


【解决方案1】:

您可以尝试activemq-node 模块,也可以在ActiveMQ 上启用STOMP protocol 并使用this node.js 库。

【讨论】:

  • 嗨乔希,非常感谢您的帮助。我尝试使用 stomp 并且它有效。但是我遇到了一个小问题,您能否查看我的编辑以获取更多详细信息并帮助我?
【解决方案2】:

你需要添加一个标题:

client.publish(destination, 'your content', {
    "amq-msg-type": "text"
});

https://issues.apache.org/jira/browse/AMQ-2833

【讨论】:

    猜你喜欢
    • 2017-05-18
    • 2012-01-13
    • 2018-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 2019-01-16
    相关资源
    最近更新 更多