Home  >  Article  >  Java  >  JMS Active MQ message transmission (detailed graphic and text explanation)

JMS Active MQ message transmission (detailed graphic and text explanation)

怪我咯
怪我咯Original
2017-06-30 10:47:572251browse

The following editor will bring you an article on JMS Active MQ message transmission (detailed explanation). The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

This article uses Active MQ5.6

1. Message Negotiator (Message Broker)

broke: The message exchanger is the container that manages messages. ActiveMQ can create multiple Brokers. When the client interacts with ActiveMQ, it actually interacts with the Broker in ActiveMQ. The Broker is configured in ${MQ_HOME}\conf\activemq.xml.

2. Connectors (1) Transport Connectors

transportConnectors connector: It is to establish the interaction between the broker, the message producer and the message consumer.

Commonly used protocols for transport connectors:

Commonly used connection protocols in Active MQ: tcp, udp, nio, ssl, http, https,vm. If you use the ssl protocol, you need to configure a certificate. If you use http or https, you need to use httpclient to send receive messages.

(1)TCP default protocol

##tcp://hostname:port?

key=value&key=value The following parameters are optional

Benefits of using TCP protocol

Efficient: This protocol connection uses the OpenWire protocol. By converting the message into a byte stream, the performance is very good

Availability: TCP is a very widely used network protocol, basically all platforms support it

TCP configuration example conf/activemq.xml:

    <transportConnectors>
      <!--activemq 的默认连接 tcp-->
      <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
    </transportConnectors>

(2) , NIO

a. The NIO protocol is similar to the TCP protocol, but NIO focuses more on the underlying access operations. It allows developers to have more client calls and more load on the server for the same resource.

b. Scenarios suitable for using the NIO protocol:

There may be a large number of Clients connecting to the Broker. In general, the number of Clients connecting to the Broker is limited by the number of threads in the operating system. of. Therefore, the implementation of NIO requires fewer threads to run than TCP, so it is recommended to use the NIO protocol

It may be that the Broker has a very slow network transmission NIO provides better performance than TCP

c. URI form of NIO connection: nio://hostname:port?key=value. The following parameters are optional

d. NIO configuration example conf/activemq.xml:

<transportConnectors>
      <!-- 设置一个NIO的连接-->
      <transportConnector name="nio" uri="nio://0.0.0.0:61617"/>
    </transportConnectors>

(3), UDP

a, the difference between UDP and TCP

TCP is a raw stream delivery protocol, which means that the data packet is guaranteed In other words, the data packet will not be copied and lost. UDP, on the other hand, does not guarantee the delivery of data packets

TCP is also a stable and reliable data packet delivery protocol, which means that data will not be lost during delivery. This ensures reliable communication between sender and receiver. On the contrary, UDP is just a link protocol, so it has no reliability.

TCP is used in stable and reliable scenarios; UDP is usually used in scenarios where fast data transfer is not afraid of data loss. When ActiveMQ passes through the firewall, you can only use UDP

b, the URI form of UDP connection: udp://hostname:port?key=value

c, and configure the instance conf/activemq. xml

<transportConnectors>
  <transportConnector name="udp" uri="udp://localhost:61618"/>
</transportConnectors>

(4), SSL

The bottom layer is the TCP protocol, but the transmitted data is encrypted

a. Applicable scenarios: MQ is exposed to the external network and requires communication between the client and the broker.

b. Usage steps:

b-1. Create SSL protocol:

b-2. Configure Broker SSL protocol conf/activemq.xml:

 <sslContext>
  <sslContext keyStore="F:/beifeng/apache-activemq-5.6.0/conf/mybroker.ks"
   keyStorePassword="test123" />
</sslContext>

b-3. Configure client SSL protocol:

c. URI form of SSL connection: ssl://hostname:port?key=value

d, configuration instance conf/activemq.xml

<transportConnectors>
   <transportConnector name="ssl" uri="ssl://localhost:61619"/>
 </transportConnectors>

(5 ) HTTP, HTTPS

a. Receive mq messages of http protocol through jetty container

b. Used in network environments that only allow basic HTTP services to pass

c. To send/receive messages through httpclient, you need to add additional java packages Httpclient, Xstream, activemq-optional

d, URI: http://hostname:port?key=value

e. Configure instance conf/activemq.xml:

<transportConnectors>
  <transportConnector name="http" uri="http://localhost:8080"/>
</transportConnectors>


To configure HTTPS, you need to configure the relevant certificate HTTPS= HTTP+SSL

# in jetty.xml

## (2.) Network Connectors (NetWorkConnectors) NetWorkConnectors: used for the interaction between Broke and Broke, mainly when deploying ActiveMq cluster.

The above article about JMS Active MQ message transmission (detailed explanation) is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home.

The above is the detailed content of JMS Active MQ message transmission (detailed graphic and text explanation). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn