RABBITMQ installation and use in Windows environment

Source: Internet
Author: User
Tags stomp rabbitmq

Installing the RABBITMQ environment under Windows Configuration Deployment Environment

Deployment environment: Windows Server R2 Enterprise

Official installation Deployment Documentation: http://www.rabbitmq.com/install-windows.html Official Document description

Download Erlang

The reason for this is that the RABBITMQ server code is written in the Concurrency language Erlang: http://www.erlang.org/downloads or Erlang windows binaries, Double-click the. exe file to install it, create an environment variable named Erlang_home after installation, its value points to the installation directory for ERLANG, add%erlang_home%\bin to path, and finally open the command line, enter Erl, If the version information of Erlang appears, the Erlang locale is installed successfully;

Download RABBITMQ

: http://www.rabbitmq.com/, also double-click the. exe to install it (note here that the default installation directory is C:/Program files/...., there is a space in this directory, we need to change the installation directory, Seemingly RABBITMQ installation directory is not allowed to have spaces, I have stepped on this big hole before;

Installing Rabbitmq-plugins

This equates to a management interface that allows us to view RABBITMQ message queues and exchange work in the browser interface by opening a command line CD into the RABBITMQ sbin directory (my directory is: E:\software\ Rabbitmq\rabbitmq_server-3.6.5\sbin), enter: Rabbitmq-plugins enable Rabbitmq_management command, a little while, you will find the plugins installation successful prompt, The default is to install 6 plugins if you have the following error during the installation of the plugin:

The workaround is: first enter at the command line: Rabbitmq-service stop, then enter Rabbitmq-service Remove, then enter Rabbitmq-service install, Then input rabbitmq-service start, and finally re-enter Rabbitmq-plugins enable Rabbitmq_management try, I was the solution;

RABBITMQ Introduction

On the official page, download the corresponding installation package, note that the RABBITMQ installation will occupy several ports, and firewalls and other security tools may prevent RABBITMQ from binding to the port. When this happens, RABBITMQ will not start. Make sure that you can open the following ports and, of course, install them yourself by modifying the configuration file to modify the occupied ports and then turn on the service.

    • Peer discovery Services used by 4369:EPMD,RABBITMQ nodes and CLI tools
    • 5672,5671: Used by AMQP 0-9-1 and 1.0 clients without TLS and TLS
    • 25672:erlang distribution is used for inter-node and CLI tool communication and is allocated from dynamic range (by default to a single port, calculated as AMQP port + 20000). For more information, see your network guide.
    • 15672:http API client and Rabbitmqadmin (only when the management plug-in is enabled)
    • 61613,61414: No Stomp client with TLS (only stomp plug-in enabled)
    • 1883,8883:( MQTT client not and with TLS if the Mqtt plugin is enabled
    • 15674:stomp-over-websockets Client (only Web STOMP plugin enabled)
    • 15675:mqtt-over-websockets Client (only when the Web MQTT plugin is enabled)

After the installation is successful, all installed apps and plugins can be found in the Start menu.

Open service

View Web page Management

After the plug-in installation, in the browser input http://localhost:15672 to verify, you will see the following interface, enter the user name: Guest, Password: Guest You can enter the management interface, of course, you can change the user name password;

Configure Allow remote access

In more cases, the queue service is often not on our local machine, we need to control RabbitMQ remotely, but by default it cannot be accessed by http://server-name, 15672来 can be modified by \RABBITMQ Server\ Rabbitmq_server-3.6.10\etc under Rabbitmq.config to set the Allow guest user to Telnet, modify it to the following value, and then restart the RABBITMQ service in Service Manager.

The default RabbitMQ will generate a configuration file in C:\Users\Administrator\AppData\Roaming\RabbitMQ, Rabbitmq.config inside is the actual configuration information, if the diagram is convenient, can also be directly changed here.

[{rabbit, [{loopback_users, [guest]}]}].
RABBITMQ concept

Producer: Message producer

Consumer: Message Consumers

Virtual Host: In RABBITMQ, the user can only make some permission settings at the virtual host level, such as which queues I can access, which requests I can handle, etc.

Broker: The message redirector, which is the function that our RABBITMQ serves, then what is the rule for the message to be forwarded? The following concepts need to be used;

Exchange: Switch, he is and producer directly to deal with, a bit similar to the function of the router, mainly for the forwarding operation of the chant, then producer in the end with which exchange to route it? This depends on the routing key (route key), each message has this key, we can also set ourselves, is actually a string;

Queue: Message Queuing, used to hold messages, he receives messages routed by Exchange, we can persist the contents of the queue, so what does queue receive the message of that Exchange route? This is the time to use the binding key (binding keys), binding key will queue and exchange binding, as for the binding method, RABBITMQ provides a variety of ways, you can see the RABBITMQ blog series (click to see);

These are some of the concepts involved in RABBITMQ, and a graph that shows the relationship between these concepts is:

RABBITMQ Simple to use

Producer (producer) End step:

(1): Create ConnectionFactory, and set some parameters, such as Hostname,portnumber and so on

(2): Create a connection connection with ConnectionFactory

(3): Create a channel with connection

(4): Create a queue and bind to channel

(5): Create a message and send it to the queue

Note that in our current example, the exchange switch is not used, RABBITMQ will create an empty string name by default for Exchange, and if we do not create our own exchange, the default is to use this exchange;

Producer-side code (reference rabbitmq.client):

//reference rabbitmq.client, Rabbitmq.servicemodel
Public classSender {PrivateFinalStaticString queue_name ="Myqueue"; Public Static voidMain (string[] args) {send (); } Public Static voidSend () {ConnectionFactory factory=NULL; Connection Connection=NULL; Channel Channel=NULL; Try{Factory=NewConnectionFactory (); Factory.sethost ("localhost"); Connection=factory.newconnection (); Channel=Connection.createchannel (); Channel.queuedeclare (Queue_name,false,false,false,NULL); String message="My first message ... .."; Channel.basicpublish ("", Queue_name,NULL, Message.getbytes ("UTF-8")); System. out. println ("message has been sent ....."+message); } Catch(IOException e) {e.printstacktrace (); } Catch(TimeoutException e) {e.printstacktrace (); }finally{ Try { //Close ResourceChannel.close (); Connection.close (); } Catch(IOException e) {e.printstacktrace (); } Catch(TimeoutException e) {e.printstacktrace (); } } }}

Consumer (consumer) End steps:

(1): Create ConnectionFactory, and set some parameters, such as Hostname,portnumber and so on

(2): Create a connection connection with ConnectionFactory

(3): Create a channel with connection

(4): Bind the queue and channel, note that the queue name here is consistent with the queue created earlier producer

(5): Create consumer consumer to receive messages while binding consumers and queue

Consumer-side code:

         Public classReceiver {PrivateFinalStaticString queue_name ="Myqueue";  Public Static voidMain (string[] args) {receive (); }         Public Static voidreceive () {ConnectionFactory factory=NULL; Connection Connection=NULL; Channel Channel=NULL; Try{Factory=NewConnectionFactory (); Factory.sethost ("localhost"); Connection=factory.newconnection (); Channel=Connection.createchannel (); Channel.queuedeclare (Queue_name,false,false,false,NULL); Consumer Consumer=NewDefaultconsumer (channel) {@Override Public voidhandledelivery (String consumertag, Envelope Envelope, basicproperties properties,byte[] body) throws IOException {System. out. println ("11111111111"); String message=NewString (Body,"UTF-8"); System. out. println ("Receive Message ....."+message);            }}; Channel.basicconsume (Queue_name,true, consumer); } Catch(IOException e) {e.printstacktrace (); } Catch(TimeoutException e) {e.printstacktrace (); }finally{            Try {                //Close ResourceChannel.close ();            Connection.close (); } Catch(IOException e) {e.printstacktrace (); } Catch(TimeoutException e) {e.printstacktrace (); }        }    }}

RABBITMQ installation and use in Windows environment

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.