JMS学习(二)之ActiveMQ

1,ActiveMQ是Apache实现的基于JMS的一个消息服务器。下面记录ActiveMQ的一些基本知识。

2,ActiveMQ connectors:ActiveMQ providesconnectors, a connectivity mechanism that provides client-to-broker communications as well as broker-to-broker communications.

connectors是一种连接机制,提供client 到 broker 的连接,以及 borker 之间的连接。 broker可以理解为消息服务器。

3,一些 connectivity concepts :

1) Connector URIs, that make it possible to address brokers---Client要想连接到消息服务器,需要知道服务器的地址,即Connector URIs

ActiveMQ中默认配置好的一个URI是 tcp://localhost:61616,它就表示在61616端口上创建一个TCP连接到localhost

在ActiveMQ中 TCP连接支持自动重连。通过配置 composite URIs 实现自动重连。

2) Transport connectors, which are used to expose brokers to clients---Client连接消息服务器时,使用Transport connectors进行连接

在ActiveMQ的配置文件 conf/activemq.xml 中配置connectors。

可以修改<transportConnector>添加新的连接。修改配置文件后,需要重启ActiveMQ生效。

Client连接Broker可用的协议有:

1)Tcp协议。提供可靠连接

wire protocol:How messages are serialized from and to a byte-sequence is defined by the wire protocol.

由于网络之间只能传输字节流,故需要序列化。wire protocol 就是用来定义序列化方式的。ActiveMQ中默认的 wire protocol 是OpenWire.

OpenWire main purpose is to be network efficient and allow fast exchange of messages over the network.

总之,就是 the TCP transport connector is used to exchange messages serialized to OpenWire wire format over the TCP network.

2)NIO New I/O API Protocol

对于NIO,它底层还是使用TCP传输协议,并使用OpenWire作为序列化协议。但是 transport connector 的实现使用的是 NIO API。使用NIO的好处如下:

You have a large number of clients you want to connect to the broker。---支持大量的客户端连接,因为相对于TCP Transport connector,NIO connector处理的每个client所需要的线程很少。

You have a heavy network traffic to the broker。---当网络流量较大时,也可以使用NIO

配置使用NIO的示例图如下:

 可以看出,基本与TCP配置一致,只是NIO所用的端口为61618

3) Network connectors, which are used to create networks of brokers---提供 各个 broker 之间的连接

4) Discovery Agents, that allow the discovery of brokers in a cluster

原文地址:https://www.cnblogs.com/hapjin/p/5434566.html