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

RabbitMQ installation configuration and basic use based on EasyNetQ driver

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

RabbitMQ basic concepts and principles

AMQP (Advanced Message Queuing Protocol) is an open standard for application layer protocols designed for message-oriented middleware.

RabbitMQ is an open source AMQP implementation written in Erlang on the server side.

3.Channel

Channel is the most important interface we deal with RabbitMQ. Most of our business operations are completed in Channel, including defining Queue, defining Exchange, binding Queue and Exchange, publishing messages, etc.

4. Exchange (producer sends messages to Exchange), Exchange routes messages to one or more Queue (or drops), RabbitMQ commonly used Exchange Types are fanout, direct, topic, headers)

Queue (internal object of RabbitMQ for storing messages)

6. basic working principle

Client (Producer) send Message -->Exchange (Switch saves messages to the corresponding queue by different types)-->Queue

Clients (consumers) consume messages in the queue through subscriptions.

The above basic concepts are collated from RabbitMQ basic concepts. Detailed introduction

Installing RabbitMQ on Windows

1. Download and install erlang (I use otp_win64_19.3 version)

Download http://www.erlang.org/downloads (32 or 64 bits depending on operating system)

2. Download and install rabbitmq-server (I use rabbitmq-server-version 3.6.10)

Download address http://www.rabbitmq.com/install-windows.html

After installation, you can see it under the installation directory.

Next, use the Enable DOS command

a. cd to sbin directory, my installation directory is D:\RabbitMQServer\rabbitmq_server-3.6.10\sbin, enter D: Enter, cd RabbitMQServer\rabbitmq_server-3.6.10\sbin

b. Command: rabbitmqctl status

c. Install Management Plugins Command: rabbitmq-plugins enable rabbitmq_management

Install successfully, enter http://127.0.0.1:15672/in your browser

Enter guest account guest password, successfully logged in, is not a little excited.

The guest account is an administrator account and can add Exchanges, Queues, Admin. However, we generally do not use guest accounts, and continue to use commands to add accounts and permissions.

d: add user: rabbitmqctl.bat add_user username password

e: Add Super Administrator role: rabbitmqctl.bat set_user_tags username administrator

The mymq account is also a super administrator. Can access virtual hosts: No access. You can see virtual machines that are not yet accessible. Next, add virtual machines.

f: Add virtual machine: rabbitmqctl add_vhost vhostName

myvhost virtual machine does not have Users. Next, bind the virtual machine account.

g: Set VM and user permissions: rabbitmqctl set_permissions -p VM name Account name ".* " ".* " ".* "

h: I'm used to deleting guest accounts: rabbitmqctl.bat delete_user username

All right, log in to the management page again, everything is normal, and then start the actual combat.

EasyNetQ is installed in the basic usage project of EasyNetQ

EasyNetQ is dependent on RabbitMQ.Client, so it will be installed into the project as well.

Publish Publish Message

Model has a Queue attribute that defines Queue name and Exchange name. Then directly use Publish method to push Msg to the designated queue through the switch specified by Model.

Run the code and see MQ's admin page.

TestQueue.Exchange, Type:topic , Features:D. D:Durable indicates that switches created by default are persistent.

Because there are no subscriptions yet, the corresponding queues are not visible in Queues.

Subscribe Subscribe Message

Why put a while(true) on the subscription code? This is to simulate console programs as Windows services, because console programs run in a flash and there is no way to actually subscribe to MQ messages.

In actual development, Topself is generally used to publish console programs as Windows services, and there is time to write a study blog about Topself later.

Repeat the Publish operation to test the whole process.

Custom Topic

This message is sent to all Queue queues whose names begin with Test.

Send and Receive

Send and receive allow messages to be sent to a specified queue.

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

Servers

Wechat

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

12
Report