学习笔记:ActiveMQ的传输协议

ActiveMQ的传输协议

ActiveMQ支持的网络协议

不同的配置,MQ性能是不一样的

官网拜读:https://activemq.apache.org/connectivity

(1)Transmission Control Protocol(TCP)-- 默认

1 .这是默认的Broker配置,TCP的Client监听端口616162.在网络传输数据前,必须要序列化数据,消息是通过一个叫wire protocol的来序列化成字节流。

2、默认情况下ActiveMQ把wire protocol叫做OpenWire,它的目的是促使网络上的效率和数据快速交互。

3、TCP连接的URI形式如:tcp://hostname:port?key=value&key=value,后面的参数是可选

4、TCP传输的优点:
(4.1)TCP协议传输可靠性高,稳定性强

(4.2)高效性:字节流方式传递,效率很高
(4.3)有效性、可用性:应用广泛,支持任何平台                                                                                                        

5、关于Transport协议的可配置参数可以参考官网:http://activemq.apache.org/configuring-version-5-transports.html

 

2)New I/O API Protocol(NIO)

ActiveMQ支持的client-broker通讯协议有:TCP、NIO、UDP、SSL、Http(s)、VM。

其中配置 Transport Connector 的文件在activeMQ安装目录的 conf/activemq.xml 中的 <transportConnectors> 标签之内。
 

1.NIO协议和TCP协议类似但NIO更侧重于底层的访问操作。它允许开发人员对同一资源可有更多的client调用和服务端有更

多的负载

2. 适合使用NIO协议的场景:

(2.1)可能有大量的Client去连接到Broker上,一般情况下,大量的Client去连接Broker是被操作系统的线程所限制的。因此,NIO的实现比TCP需要更少的线程去运行,所以建议使用NIO协议

(2.2)可能对于Broker有一个很迟钝的网络传输,NIO比TCP提供更好的性能。

3. NIO连接的URI形式:nio/hostname:port?key = value

4.Transport Connector配置示例,参考官网去:

http://activemq.apache.org/configuring-version-5-transports.html
 

The NIO Transport

Same as the TCP transport, except that the New /O(NIO) package is used, which may provide better performance. The Java NIO package should not be confused with IBM's AlO4Jpackage.

To switch from TCP to Nlo, simply change the scheme portion of the URl. Here's an example as defined within a broker's XML configuration file.
 

<broker>
  ...
  <transportConnectors>
    <transportConnector name="nio" uri="nio://0.0.0.0:61616"/>  
  </<transportConnectors>
  ...
</broker>

3)AMQP 协议

即Advanced Message Queuing Protocol,一个提供统一消息服务的应用层标准高级消息队列协议,是应用层协议的一个开

放标准,为面向消息的中间件设计。基于此协议的客户端与消息中间件可传递消息,并不受客户端/中间件不同产品,不同

开发语言等条件的限制。

ActiveMQ supports the AMQP 1.0 protocol which is an OASIS standard.
 

Availability

Available from ActiveMQ version 5.8 onward.

Enabling the ActiveMQ Broker for AMQP

To enable AMQP protocol support on the broker add the following transport connector Configuration referencing the amqp scheme in its URl:

<transportConnectors>
    <transportconnector name="amqp"uri="amqp://0.0.0.0:5672"/>
</transportConnectors>


It is enabled in the default ActiveMQ server configuration.For more help see Run Broker.
 

(4)MQTT协议

MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)是IBM开发的一个即时通讯协议,有可能成为物联网

的重要组成部分。该协议支持所有平台,几乎可以把所有联网物品和外部连接起来,被用来当做传感器和致动器(比如通

过Twitter让房屋联网)的通信协议。

懒得看官网版:https://s2.ax1x.com/2019/08/29/mL4W38.png
 

Enabling the ActiveMQ Broker for MQTT

Its very easy to enable ActiveMQ for MQTT. Just add a connector to the broker using the MQTT URL.

<transportConnectors>
   <transportConnector name="mqtt" uri="mqtt://localhost:1883"/>
</transportConnectors>

(5)Secure Sockets Layer Protocol(SSL)

连接的URL形式:ssl://hostname:port?key=value

2、Transport Connector配置示例:

<transportConnectors>
   <transportConnector name="ssl" uri="ssl://localhost:61618?trace=true"/>
</transportConnectors>


 

6)STORM 协议

STOMP,Streaming Text Orientated Message Protocol,是流文本定向消息协议,是一种为MOM(Message Oriented

Middleware,面向消息的中间件)设计的简单文本协议。

官网拜读:https://activemq.apache.org/stomp
 

(7)WebSocket  -- ws 协议

还是拜读官网吧:https://activemq.apache.org/websockets

2.3、NIO性能增强


(1)配置了 NIO 后性能应该可以,有没有更进一步的优化?

URI 格式头以 "nio” 开头,表示这个端口使用以TCP 协议为基础的 NIO 网络 IO 模型。但是这样的设置方式,只能使这个端

口支持 Openwire 协议。怎么既让这个端口支持 NIO 网络 IO 模型,又让它支持多个协议呢?

(2)使用auto关键字

依旧是官网拜读:https://activemq.apache.org/auto

Enabling AUTO over NIO


To configure ActiveMQ auto wire format detection over an NIO TCP connection use the auto+nio transport prefix. For example, add the following transport configuration in your XML file:
 

3)使用“+”符号来为端口设置多种特性

如果您不特别指定 ActiveMQ 的网络监听端口,那么这些端口都将使用 BIO 网络 IO 模型。(OpenWire,STOMP,AMQP..

…)

所以为了首先提高单节点的网络吞吐性能,我需要明确指定Active的网络IO模型,如下所示:URI 格式头以 ”nio” 开头,表

示这个端口使用以TCP协议为基础的 NIO 网络 IO 模型。
 


 

猜你喜欢

转载自blog.csdn.net/m0_46405589/article/details/115131113