連線器
在啟動 Broker 後,您會需要將客戶端連線至它。因此,讓我們先比較 ActiveMQ 和 Artemis 在客戶端連線器領域的設定。在 ActiveMQ 的術語中,它們稱為傳輸連線器,預設組態如下 (在 conf/activemq.xml
中)。
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
在 Artemis 中,客戶端連線器稱為接收器,它們在 etc/broker.xml
中設定,如下所示
<acceptors>
<acceptor name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE</acceptor>
<acceptor name="amqp">tcp://0.0.0.0:5672?protocols=AMQP</acceptor>
<acceptor name="stomp">tcp://0.0.0.0:61613?protocols=STOMP</acceptor>
<acceptor name="hornetq">tcp://0.0.0.0:5445?protocols=HORNETQ,STOMP</acceptor>
<acceptor name="mqtt">tcp://0.0.0.0:1883?protocols=MQTT</acceptor>
</acceptors>
您可以注意到語法非常相似,但仍然有一些我們需要理解的差異。首先,如我們之前所說,Artemis 中沒有區分阻塞和非阻塞 (nio) 傳輸的概念,因此您應將所有內容視為非阻塞。此外,在 Artemis 中,底層傳輸與在其之上使用的實際訊息協定(例如 AMQP 或 MQTT)是不同的。一個接收器可以在同一個埠上處理多個訊息協定。預設情況下,所有協定都接受在單一埠上,但您可以使用 protocols=X,Y
URI 屬性模式來限制此設定,如上述範例所示。
除了 tcp 網路協定之外,Artemis 還支援 InVm 和 Web Socket 傳輸。InVm 傳輸類似於 ActiveMQ 的 vm 傳輸,用於將客戶端連線至嵌入式 Broker。不同之處在於,您可以在 Artemis 的 InVm 傳輸之上使用任何訊息協定,而 ActiveMQ 中的 vm 傳輸則綁定到 OpenWire。
使用 Netty 作為 IO 層的優勢之一是,Web Socket 開箱即用。因此,不需要像 ActiveMQ 中那樣單獨的 ws 傳輸,Artemis 中的 tcp (Netty) 接收器會偵測 Web Socket 客戶端並相應地處理它們。
為了總結這個主題,這裡有一個表格,顯示如何將 ActiveMQ 傳輸連線器遷移到 Artemis 接收器
ActiveMQ | Artemis(接收器 URL 中的選項) |
---|---|
OpenWire | protocols=OpenWire (版本 10+) |
NIO | - |
AMQP | protocols=AMQP |
STOMP | protocols=STOMP |
VM (僅限 OpenWire) | InVM (所有協定,與 tcp 對等) |
HTTP (基於 OpenWire) | - |
MQTT | protocols=MQTT |
WebSocket (STOMP 和 MQTT) | 由 tcp 處理(所有協定) |