Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to monitor and hear RabbitMQ send messages and complete data monitoring at the front end

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

How to hear RabbitMQ send messages and complete data monitoring at the front end, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

How to achieve real-time monitoring of RabbitMQ messages in the front end, and this also involves the knowledge blind area of the editor, so the road of learning begins, and then follow the editor to learn about how to monitor RabbitMQ messages in the front end in order to achieve the functions of your own project.

Protocols supported by RabbitMQ

Stomp protocol

The stomp protocol, Simple (or Streaming) Text Orientated Messaging Protocol, a simple (streaming) text-oriented message protocol, provides an interoperable connection format that allows STOMP clients to interact with any STOMP message broker (Broker). Because of its simple design and easy to develop client, STOMP protocol has been widely used in many languages and platforms.

In the next article, we will mainly talk about how stomp listens to RabbitMQ.

The predecessor of stomp protocol is TTMP protocol (a simple text-based protocol), which is designed for messaging middleware.

This sentence is specifically designed for message-oriented middleware. In fact, it is not for the front-end use of RabbitMQ, but for the use of message middleware as a whole.

2.mqtt protocol

There is also a frequently used mqtt protocol, the full name of mqtt protocol (Message Queuing Telemetry Transport, message queuing telemetry transmission protocol), is a publish / subscribe (Publish/Subscribe) mode based lightweight communication protocol, this protocol is built on the TCP/IP protocol, released by IBM in 1999, the latest version is v3.1.1.

Mqtt protocol belongs to the application layer protocol, which means that mqtt. TCP/IP can be used wherever the mqtt stack is supported.

RabbitMQ launches stomp protocol

Install RabbitMQ tutorial A Fan will no longer tell you, after all, there are many articles on Baidu to tell you how to install RabbitMQ, whether it is Linux or Windows, we just need to pay attention to that, first install erlang language support, otherwise you can not install RabbitMQ.

Activate Stomp protocol:

Rabbitmq-plugins enable rabbitmq_web_stomp rabbitmq-plugins enable rabbitmq_web_stomp_examples # restart service rabbitmq-server stop & & service rabbitmq-server start

When we turn it on, make it visible in our RabbitMQ, as shown in the figure:

As you can see, after we opened it correctly, on the console of RabbitMQ, we can see that the port of http/web-stomp is 15674.

Next we are going to write a case for testing.

Front-end Stomp listens to RabbitMQ

If we send a message to the message queue at this time, then it will show what we need on the page.

Let's see how the code is written.

If (typeof WebSocket = = 'undefined') {console.log (' does not support websocket')} / / initialize ws object var ws = new WebSocket ('ws://localhost:15674/ws'); / / get Stomp client object var client = Stomp.over (ws) / / define the callback function var on_connect = function (x) {/ / data.body is the received data client.subscribe ("/ Fanout_Exchange/testMessage", function (data) {var msg = data.body; alert ("received data:" + msg);});} / / callback function var on_error = function () {console.log ('connection error, please try again'); / / connect RabbitMQ client.connect ('guest',' guest', on_connect, on_error,'/'); console.log ("> RabbitMQ is connected, test begins")

And the content written in this is more interesting, because before many people will find that no matter how to write, it is not good, that is because there is no complete understanding, A Fan finally summed up the use of Stomp.

Summary

1./exchange/ (exchangeName)

For SUBCRIBE frame,destination it is generally in the form of / exchange/ (exchangeName) / [/ pattern]. The destination creates a unique, automatically deleted queue named (exchangeName), and binds the queue to the given exchange based on the pattern to implement message subscriptions to the queue.

For SEND frame,destination it is generally in the form of / exchange/ (exchangeName) / [/ routingKey]. In this case, the message is sent to the defined exchange, and the routingKey is specified.

2./queue/ (queueName)

For SUBCRIBE frame,destination, a shared queue is defined (queueName), and message subscriptions to the queue are implemented.

For SEND frame,destination, the shared queue is only defined (queueName) the first time the message is sent. The message is sent to the default exchange, where routingKey is (queueName).

3./amq/queue/ (queueName)

In this case, neither SUBCRIBE frame nor SEND frame will produce queue. But if the queue does not exist, the SUBCRIBE frame will report an error.

For SUBCRIBE frame,destination, message subscriptions to queues (queueName) are implemented.

For SEND frame, messages are sent directly to the queue (queueName) through the default exhcange.

4./topic/ (topicName)

Create an automatically deleted, non-persistent queue for the SUBCRIBE frame,destination and bind it to the amq.topic exchange according to the (topicName) of the routingkey, while implementing the subscription to the queue.

For SEND frame, the message is sent to amq.topic exchange and the routingKey is (topicName).

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report