Installation Configuration RABBITMQ Quick Guide on Windows

Source: Internet
Author: User
Tags rabbitmq

Installing Rabbit MQ

Rabbit MQ is built on the powerful Erlang OTP platform, so installing Rabbit MQ is premised on the installation of Erlang. Download the installation from the following two connections 3.2.3 version:

    1. Download and install ERALNG OTP for Windows (VR16B03)
    2. Run Install Rabbit MQ Server Windows Installer (v3.2.3)

The default installed rabbit MQ listening port is 5672

Activate Rabbit MQ ' s Management Plugin

With the Rabbit MQ Management plug-in, you can better visualize the status of the Rabbit MQ Server instance, which you can activate at the command line using the following command:

"C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.2.3\sbin\rabbitmq-plugins.bat" enable rabbitmq_management

要重启服务才能生效,可以执行

net stop RabbitMQ && net start RabbitMQ

Below we use the Rabbitmqctl Console command (located in C:\Program Files (x86) \RABBITMQ server\rabbitmq_server-3.2.3\sbin>) to create a user, password, bind permission, and so on.

Microsoft Windows [version 6.3.9600]
(c) Microsoft Corporation. All rights reserved.

Directory of the C:\Program Files (x86) \RABBITMQ Server\rabbitmq_server-3.2.3\sbin

2014/11/01 15:04 <DIR>.
2014/11/01 15:04 <DIR>.
2014/01/23 22:57 817 Rabbitmq-echopid.bat
2014/01/23 22:57 1,900 Rabbitmq-plugins.bat
2014/01/23 22:57 4,356 Rabbitmq-server.bat
2014/01/23 22:57 7,123 Rabbitmq-service.bat
2014/01/23 22:57 1,621 Rabbitmqctl.bat
5 Files 15,817 bytes
2 Directories 96,078,618,624 bytes available

C:\Program Files (x86) \RABBITMQ server\rabbitmq_server-3.2.3\sbin>rabbitmqctl.ba
T list_users
Listing users ...
Guest [Administrator]
... done.

C:\Program Files (x86) \RABBITMQ server\rabbitmq_server-3.2.3\sbin>rabbitmqctl.ba
T list_vhosts
Listing vhosts ...
/
... done.

C:\Program Files (x86) \RABBITMQ server\rabbitmq_server-3.2.3\sbin>rabbitmqctl.ba
T Add_user Geffzhang [email protected]
Creating user "Geffzhang" ...
... done.

C:\Program Files (x86) \RABBITMQ server\rabbitmq_server-3.2.3\sbin>rabbitmqctl.ba
T list_users
Listing users ...
Geffzhang []
Guest [Administrator]
... done.

C:\Program Files (x86) \RABBITMQ server\rabbitmq_server-3.2.3\sbin>rabbitmqctl.ba
T set_user_tags Geffzhang Administrator
Setting tags for the user "Geffzhang" to [Administrator] ...
... done.

C:\Program Files (x86) \RABBITMQ server\rabbitmq_server-3.2.3\sbin>rabbitmqctl.ba
T set_permissions-p/Geffzhang ". *" ". *" ". *"
Setting permissions for the user "Geffzhang" in Vhost "/" ...
... done.

C:\Program Files (x86) \RABBITMQ server\rabbitmq_server-3.2.3\sbin>rabbitmqctl.ba
T list_users
Listing users ...
Geffzhang [Administrator]
Guest [Administrator]
... done.

Use your browser http://localhost:15672 to open the admin console that accesses rabbit MQ and use the account you just created to log in to the system:

Using rabbit MQ on. Net

Get rabbit MQ NET client bindings from NuGet with NuGet:

PM> Install-Package RabbitMQ.Client

我们最常见的一个场景是发送和接收Rabbit MQ 持久化消息:

第一步是声明durable Exchange 和 Queue

private readonly ConnectionFactory rabbitmqfactory = new ConnectionFactory {HostName = "geffzhang-nb", username= "GEF Fzhang ", Password ="[email protected]", VirtualHost ="/"};
ConstStringExchangename="Test.exchange";
ConstStringQueueName="Test.queue";

Using(IconnectionConn=Rabbitmqfactory.CreateConnection())
Using(IModelChannel=Conn.Createmodel())
{
Channel.Exchangedeclare(Exchangename,"Direct",Durable:True,Autodelete:False,Arguments:Null);

channel. Queuedeclare (queuename,durable : trueexclusive:false autodelete:falsearguments:null);
    channel. Queuebind (queuename,exchangename routingkey:queuename /span>

The above code is described below:
1. Use ConnectionFactory to create a connection, although multiple server address is specified at creation time, but each connection is connected to only one physical server.

2. Define the interchange mode, create direct exchange and durable queue, and use QueueName as the routing key , you can post the message directly to a queue. RABBITMQ exchange methods are divided into three types, namely:
Direct Exchange – Handles routing keys. A queue needs to be bound to the switch, requiring the message to exactly match a specific routing key. This is a complete match. If a queue is bound to the switch requiring the routing key "Dog", only the message labeled "Dog" is forwarded, the Dog.puppy is not forwarded, the Dog.guard is not forwarded, and only the dog is forwarded.
fanout Exchange – does not handle routing keys. You simply have to bind the queue to the switch. A message sent to the switch is forwarded to all queues that are bound to the switch. Much like a subnet broadcast, each host in the network receives a copy of the message. Fanout switch Forwarding message is the fastest.
Topic Exchange – match the routing key with a pattern. At this point the queue needs to be bound to a pattern. The symbol "#" matches one or more words, and the symbol "*" matches no more than a few words. So "audit.#" is able to match to "Audit.irs.corporate", but "audit.*" matches only to "Audit.irs".

Running the above code, you can see test.exchange Exchange binding to the created queue on the management console of rabbit MQ Test.queue

The second step is to publish the persistent message to the queue

After Exchange and queue are established, you can send messages to the queue. RabbitMq can accept byte[] data, and the string takes a utf-8 encoded byte array. To ensure that the message is persisted, you need to set Persistmode to True, see the following code:

VarProps=Channel.Createbasicproperties();
Props.setpersistent (true
var msgbody = encoding.utf8. Getbytes ( "Hello, world!" );
channel. (exchangename,routingkey :queuename,basicproperties:< span class= "n" >props,body:msgbody );
The third step is to consume the message, there are several different ways to consume messages from the queue, most commonly using basicget :

Basicgetresult Msgresponse = Channel. Basicget (QueueName, noack:true);

var msgbody = Encoding.UTF8.GetString (msgresponse.body);

Noack:true tells Rabbitmq to immediately delete messages from the queue, and another very popular way is to remove the messages that have been acknowledged from the queue, which can be confirmed by calling Basicack alone:

Basicgetresult msgresponse = Channel. Basicget(queuename,noack:false);

Process message ...

Channel. Basicack(msgresponse. Deliverytag,multiple:false);
It is important to use the Basicack method to tell whether to remove the message from the queue, because in some scenarios, such as getting a message from a queue and using it to manipulate a database or log file, if an operation fails, the message should remain in the queue and only be removed from the queue if the operation succeeds.

OtherOneKind of methodIsPassBased on pushOfEventSubscription。YouOKUseBuiltOfQueueingbasicconsumerProvideSimplified programming model , via allow you shared queue block , until received message For example

var consumer = new Queueingbasicconsumer (channel);

Channel. Basicconsume (QueueName, Noack:true, Consumer:consumer);

var msgresponse = consumer. Queue.dequeue (); Blocking

var msgbody = Encoding.UTF8.GetString (msgresponse.body);


Install the Rabbit MQ Guide on Windows, preferably the Rabbit MQ Windows installation guides, which also includes access Rabbit using the. NET rabbitmq.client Nuget Package Example code for MQ.

How to implement priority queues based on RABBITMQ

Https://github.com/derekgreer/rabbitBus

Https://github.com/evolvIQ/PushMQ

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Installation Configuration RABBITMQ Quick Guide on Windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.