Connecting to ActiveMQ over the network

Summary of network protocols used for client-broker communication:

(1) TCP:Default network protocol for most use cases.
(2) NIO:Consider NIO protocol if you need to provide better scalability for connections from producers
      and consumers to the broker.
(3) UDP Consider UDP protocol when you need to deal with the firewall between clients and the broker.
(4) SSL Consider SSL when you want to secure communication between clients and the broker.
(5) HTTP(S) Consider HTTP(S) when you need to deal with the firewall between clients and the broker.
(6) VM Although not a network protocol per se, consider VM protocol when your broker and clients
      communicate with a broker that is embedded in the same Java Virtual Machine (JVM).

1. Transmission Control Protocol (TCP)

     TCP 官方定义:

     The Transmission Control Protocol (TCP) is intended for use as a highly reliable host-tohost protocol

     between hosts in packet-switched computer communication networks, and in interconnected systems

     of such networks.

     TCP Connector URI Format:

     tcp://hostname:port?key=value&key=value

     定义例子:

<transportConnectors>
      <transportConnector name="tcp" uri="tcp://localhost:61616?trace=true"/>
</transportConnectors>

     TCP Connector的优点:

     (1) Efficiency

     (2) Availability

     (3) Reliability

     TCP 中传输数据是用Open Wore Protocal进行消息字节序列化的。

2. New I/O API protocol (NIO)

    New I/O是在J2SE1.4中引入的,是现存标准I/O的一个补充。NI/O Connector 与 TCP Connector一样,使用

    TCP Connector作为基本的network protocol和使用OpenWire作为消息序列化的Protocal. 特别使用NI/O的场

    景有下面两个地方:

    (1) 大批量的Client 需要连接至Broker;

    (2)  至Broler有非常严重的网络Traffic.

    TCP Connector URI:

    nio://hostname:port?key=value

    配置示例:

<transportConnectors>
	<transportConnector name="tcp" uri="tcp://localhost:61616?trace=true" />
	<transportConnector name="nio" uri="nio:localhost:61618?trace=true" />
</transportConnectors>

3. User Datagram Protocol (UDP)

    UDP 与 TCP 的目的和作用都是一样的,但两者之间有区别:

    (1) TCP 是stream-oriented protocol,即数据包不可能被复制或者是顺序错乱;

    (2) TCP 确保数据包的传输的稳定的,不会丢失。

    UDP Connector URI Format:

    udp://hostname:port?key=value

<transportConnectors>
	<transportConnector name="tcp" uri="tcp://localhost:61616?trace=true" />
	<transportConnector name="udp" uri="udp://localhost:61618?trace=true" />
</transportConnectors>

     适合使用UDP的场景:

     (1) Broker位于防火墙之后,而且只能通过UDP 端口访问Broker;

     (2) 即时的消息。

4. Secure Sockets Layer Protocol (SSL)

    ActiveMQ 使用Java Secure Socket Extension (JSSE)来实现SSL功能。

    SSL Connector URI Format:

    ssl://hostname:port?key=value

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

     创建自己的SSL Resource参考:ActiveMQ in Action.pdf: 70-73-77

5. Hypertext Transfer Protocol (HTTP/HTTPS)

     ActiveMQ 实现的HTTP Transport Connector提供了基于HTTP Protocal进行XML格式的消息交换,很容易通过

     防火墙的限制。

     HTTP URI Format:

     http://hostname:port?key=value

     HTTPS URI Format:

     https://hostname:port?key=value

<transportConnectors>
	<transportConnector name="tcp" uri="tcp://localhost:61616?trace=true" />
	<transportConnector name="http" uri="http://localhost:8080?trace=true" />
</transportConnectors>

6. Connecting to ActiveMQ inside the virtual machine (VM connector)

    VM transport connector用于在Application 中启动一个内嵌的Broker, 使用VM transport 意味着Client和Broker

    之间没有network, Cient 与Broker之间是直接的通信。

    VM URL Format:

    vm://brokerName?key=value

    例如:

    vm://broker1?marshal=false&broker.persistent=false

    或者也可配置成:

    vm:broker:(transportURI,network:networkURI)/brokerName?key=value

猜你喜欢

转载自springsfeng.iteye.com/blog/1617932
今日推荐