项目作者: chatopera

项目描述 :
在Node.js应用中集成ActiveMQ服务
高级语言: JavaScript
项目地址: git://github.com/chatopera/node-activemq.git
创建时间: 2018-08-09T07:13:05Z
项目社区:https://github.com/chatopera/node-activemq

开源协议:Other

下载


Node.js ActiveMQ Get Started

在Node.js应用中集成ActiveMQ服务。

chatoper banner

Java Messaging Service, 在多个服务之间通信,为了增强系统可靠性,经常使用消息总线作为异步通信的方案。

消息总线接通了“生产者(Producer)” 和 “消费者 (Consumer)”。
而且二者在消息总线内是“发布”和“订阅”的关系。生产者发布,消费者订阅。
消息被发送到一个地址,地址有两种类型:queue, topic。

Topic: 在一个地址下,可接受多个消费者,一个消息被生产者发送后,路由到每个消费者。
Queue: 在一个地址下,可接受多个消费者,一个消息被生产者发送后,消息只路由到一个消费者,不同消费者是同等的,竞争的。

ActiveMQ是JMS的一个实现。

docs

  1. cd app
  2. npm install
  3. cd ../admin
  4. ./test.sh

api

http://jmesnil.net/stomp-websocket/doc/

建立连接

index.js

测试

activemq.test.js

stomp 规范

http://stomp.github.io/stomp-specification-1.1.html

ActiveMQ

https://activemq.apache.org/per-destination-policies.html

注意

  1. 设置header

发送消息时,必须设置header中,必须设置

  1. "content-length": false

否则消费者端不能正常识别Body。

  1. 发送地址

/topic开始的地址,会以topic类型发送,并且在ActiveMQ中,会去掉/topic
其他情况是 queue类型。

  1. 消息的优先级

header中可以设置priority,并且

  1. JMS defines a ten-level priority value, with 0 as the lowest priority and 9
  2. as the highest. In addition, clients should consider priorities 0-4 as
  3. gradations of normal priority and priorities 5-9 as gradations of expedited
  4. priority.
  5. JMS does not require that a provider strictly implement priority ordering
  6. of messages; however, it should do its best to deliver expedited messages
  7. ahead of normal messages.
  8. ActiveMQ observes three distinct levels of "Priority":
  9. Default (JMSPriority == 4)
  10. High (JMSPriority > 4 && <= 9)
  11. Low (JMSPriority > 0 && < 4)