Installation of local RABBITMQ services under Windows

Source: Internet
Author: User
Tags rabbitmq rabbitmq tutorial amq

Installation of local RABBITMQ services under Windows

This article refers to: Liu Joeze Related Technical documents

Of course, these content pages can be obtained through the RABBITMQ official website.

RABBITMQ Configuration Instructions Manual

One, RAIBBITMQ server configuration

1. Ready to work. If you have previously installed the RABBITMQ software, if you want to reinstall, you must first uninstall the previous RABBITMQ related software.

2. Install the Erlang language pack. First, you download Erlang Windows Binary file and run it to the http://www.erlang.org/download.html page. The process is about 5 minutes.

To install the specific process:

1. Double-click Otp_win32_r16801.exe (different versions may be named differently), select Next

2. Installed on the C drive by default, it is recommended that the program be installed on a non-system disk such as D (if installation in C drive may have some permissions problems), after modifying the installation path, select Next:

3. Go to the installer and select Install to complete the installation:

3. Install the RABBITMQ Server software. To this page to download:

Http://www.rabbitmq.com/releases/rabbitmq-server/v3.1.3/rabbitmq-server-3.1.3.exe. Then run the installation.

To install the specific process:

1. Double-click Rabbitmq-server-3.1.1.exe. Select Next:

2. Install on C drive by default and install directly:

3. Approximately two minutes to complete the installation

4. If you want Rabbitmq-sever to run under the command line under Windows, you also need to configure the environment variables:

The configuration is as follows: Selecting advanced system settings will bring up the system settings, and then select the environment variables in the system settings (note the red circle)

Locate the path variable in the environment variable:

Double-click Path, add:%rabbitmq_server%\sbin (note the preceding semicolon), and then OK

Now open the Windows command line ("cmd"), enter Rabbitmq-service if the prompt appears as follows, the environment variable is configured successfully.

5. The rabbit also comes with a monitoring function.
CMD into the sbin directory, type rabbitmq-plugins enable rabbitmq_management enabling monitoring management, and then restart the RABBITMQ server. Open URL http://localhost:55672, user name and password are guest.

6. Now open the browser, enter: http://localhost:15672/, if the following page appears, the server configuration is successful.

Default user name is guest, password: Guest

If the above page does not appear, try to enter (run as Administrator) on the Windows command line:

Rabbitmq-plugins Enable Rabbitmq_management

Then run the following command to install:

Rabbitmq-service stop

Rabbitmq-service Install

Rabbitmq-service start

Second, compile RIBBITMQ with VS2010

1. Download Rabbitmq-c-master Source code

2. Download Rabbitmq-codegen Source code

3. Copy the contents of the Rabbitmq-codegen to the CodeGen directory in the Rabbitmq-c-master (if it is not available, create it yourself).

4. Download the CMake and install it.

Press Next to install directly:

Here you can change the path (note that the installation path does not contain Chinese), and the installation is complete. The desktop will then generate a Cmake_gui shortcut.

5. Compile rabbitmq-c source code using CMake.

Open CMake.

Source (red circle) fill in your rabbitmq-c-master source path, such as I put in d:/rabbitmq-c-master At the bottom of the build (yellow circle), fill in the following build folder in your source (if no build folder is created)

Point configure, you will be asked what compiler to choose, select VS2010.

Click Finish. At this point CMake will start compiling, but in a moment he may pop up the following error message:

Remove Enable_ssl_support directly, then press configure.

Wait for the compilation to complete, then click the Generate button. The entire compilation process is complete.

6. Open VS2010. Open the Rabbitmq-c.sln project under Rabbit-c-master/build with VS2010

7. Click build/Build Solution (or press F7)

8. The project will now generate good:

9. Place D:\rabbitmq-c-master\build\librabbitmq\Debug under (note D:\rabbitmq-c-master\build for the previous CMake compile makefile path, same as below) The Rabbitmq.1.dll dynamic Connection library is copied to the D:\rabbitmq-c-master\rabbitmq-c-master\build\examples\Debug folder.

10. Now all the rabbit-c example are ready to run. At this point, you can follow the instructions on HTTPS://GITHUB.COM/ALANXZ/RABBITMQ-C to perform the test.

Open "cmd" and go to the D:\rabbitmq-c-master\build\examples\Debug folder:

Enter Amqp_listen.exe localhost 5672 amq.direct test:

And in another cmd, it also reaches D:\rabbitmq-c-master\build\examples\Debug.

Input amqp_sendstring.exe localhost 5672 amq.direct test

"Hello World"

After running, if the first terminal appears as follows, the entire RABBITMQ configuration is successful.

At this point, the RAABIT-C client and server are both successful.

RABBITMQ Instructions for use

First, the basic concept:

(i) Basic concepts

RABBITMQ is a popular open source Message Queuing system, developed in Erlang language. I used to be interested in this language, studied for some time, and later did not insist. RABBITMQ is the standard implementation of the AMQP (Advanced Message Queuing protocol). If you are unfamiliar with AMQP, it can be difficult to see RABBITMQ documents directly. But it also has only a few key concepts, which are briefly described here.

The structure diagram of the RABBITMQ is as follows:

Several concept notes:

Broker: The Message Queuing server entity is simply the case.
Exchange: A message switch that specifies what rules the message is routed to and to which queue.
Queue: A message queue carrier in which each message is put into one or more queues.
Binding: Bind, which is the role of binding exchange and queue according to routing rules.
Routing key: The routing keyword, exchange messages are delivered based on this keyword.
Vhost: Virtual host, a broker can open multiple vhost, as a separate user permissions.
Producer: The message producer is the program that delivers the message.
Consumer: The message consumer is the program that receives the message.
Channel: The message channels, in each connection of the client, multiple channels can be established, each channel represents a session task.

The use of Message Queuing is probably as follows:

(1) The client connects to the Message Queuing server and opens a channel.
(2) The client declares an exchange and sets the related properties.
(3) The client declares a queue and sets the related properties.
(4) The client uses routing key to establish a good binding relationship between Exchange and queue.
(5) Clients post messages to exchange.

When Exchange receives a message, it routes messages to one or more queues based on the key of the message and the binding that has been set.

There are several types of exchange, which are called direct switches that are delivered entirely according to key, for example, when the routing key is set to "ABC", the client submits a message that only the key "ABC" is set to be posted to the queue. When the key is matched with a pattern, it is called a topic switch, and the symbol "#" matches one or more words, and the symbol "*" matches exactly one word. For example, "abc.#" matches "Abc.def.ghi", "abc.*" matches only "Abc.def". There is also a need for a key, called the fanout Switch, which takes broadcast mode, when a message comes in, it is posted to all queues that are bound to the switch.

RABBITMQ supports the persistence of messages, that is, data is written on disk, and for data security reasons, I think most users will choose to persist. Message Queuing persistence consists of 3 parts:
(1) Exchange persistence, specifying durable + 1 at the time of declaration
(2) Queue persistence, specify durable when declaring = 1
(3) Message persistence, specifying Delivery_mode = 2 (1 non-persistent) on delivery

If both Exchange and queue are persisted, then the binding between them is persistent. If there is a persistence between Exchange and queue, a non-persisted, binding is not allowed.

RABBITMQ-C Client Usage Instructions

Rabbitmq-c is a client library for the C language that interacts with the AMQP server, and the AMQP protocol is version 0-9-1. The login operation is required before RABBITMQ-C interacts with the server, and after operation, a series of operations can be performed according to the AMQP protocol specification.

Here, according to the project requirements, only part of the interface description, the text is attached to the GitHub address of the demo.

Interface Description:

amqp_connection_state_t amqp_new_connection (void);

Interface Description: Declares a new AMQP connection

int Amqp_open_socket (char const *hostname, int portnumber);

Interface Description: Gets the socket.

Parameter description: hostname RabbitMQ Server Host

PortNumber RabbitMQ Server Listener port

void Amqp_set_sockfd (amqp_connection_state_t state,int sockfd);

Interface Description: Bind AMQP connection and SOCKFD

amqp_rpc_reply_t Amqp_login (amqp_connection_state_t State, char const *vhost,int channel_max,int frame_max,int Heartbeat,amqp_sasl_method_enum Sasl_method, ...);

Interface Description: Used to log in to RABBITMQ server, the main purpose in order to conduct rights management;

Parameter description: State AMQP Connection

Vhost RABBIT-MQ Virtual Machine host is the smallest unit of RABBIT-MQ for Rights management

Channel_max Maximum number of links, set here to 0

Frame_max the maximum frame size allowed when communicating with the client. The default value is 131072, which increases this value to help increase throughput and reduces the time delay

Heartbeat meaning unknown, default value 0

Sasl_method used for SSL authentication, the default value is referenced in the following text demo

amqp_channel_open_ok_t *amqp_channel_open (amqp_connection_state_t State, amqp_channel_t channel);

Interface Description: For associating Conn and channel

amqp_exchange_declare_ok_t *amqp_exchange_declare (amqp_connection_state_t State, amqp_channel_t channel, Amqp_bytes _t Exchange, amqp_bytes_t type, amqp_boolean_t passive, amqp_boolean_t durable, amqp_table_t arguments);

Interface Description: Declaration declare

Parameter description: state

Channel

Exchange

Type "Fanout" "Direct" "topic" three Select one

Passive

Curable

Arguments

amqp_queue_declare_ok_t *amqp_queue_declare (amqp_connection_state_t State, amqp_channel_t channel, amqp_bytes_t Queue, amqp_boolean_t Passive, amqp_boolean_t Durable, amqp_boolean_t exclusive, amqp_boolean_t Auto_delete, amqp_table _t arguments);

Interface Description: Declaring a queue

Parameter description: State AMQP Connection

Channel

Queue queue Name

Passive

Durable whether the queue is persisted

Exclusive whether the queue is automatically deleted when the current connection is not present

Aoto_delete the queue is automatically deleted when there is no consumer

Arguments for expanding parameters, such as X-ha-policy for mirrored queue

amqp_queue_bind_ok_t *amqp_queue_bind (amqp_connection_state_t State, amqp_channel_t channel, amqp_bytes_t queue, AMQP _bytes_t Exchange, amqp_bytes_t routing_key, amqp_tab le_t arguments);

Interface Description: Declaring a binding

amqp_basic_qos_ok_t *amqp_basic_qos (amqp_connection_state_t State, amqp_channel_t Channel, uint32_t prefetch_size, uint16_t Prefetch_count, amqp_boolean_t Global);

Interface Description: QoS is quality of service, we use here primarily to control the number of prefetch messages, to avoid messages evenly distributed by the number of lines, need to use with No_ack

Parameter description: state

Channel

Prefetch_size in bytes, 0 for unlimited

Prefetch_count pre-fetching number of message bars

Global

amqp_basic_consume_ok_t *amqp_basic_consume (amqp_connection_state_t State, amqp_channel_t channel, amqp_bytes_t Queue, amqp_bytes_t Consumer_tag, amqp_boolean_t no_local, amqp_boolean_t No_ack, amqp_boolean_t exclusive, Amqp_table_ t arguments);

Interface Description: Start a queue consumer

Parameter description: state

Channel

Queue

Consumer_tag

No_local

No_ack If you need to confirm the message and then delete the message from the queue

Exclusive

Arguments

int Amqp_basic_ack (amqp_connection_state_t state,amqp_channel_t channel,uint64_t delivery_tag,amqp_boolean_t multiple);

int Amqp_basic_publish (amqp_connection_state_t state,amqp_channel_t channel,amqp_bytes_t exchange,amqp_bytes_t routing_key,amqp_boolean_t mandatory,amqp_boolean_t immediate,struct amqp_basic_properties_t_ const *properties, amqp_bytes_t body);

Interface Description: Publish message

Parameter description: state

Channel

Exchange

Routing_key when Exchange is the default "", fill in queue_name here, when Exchange is direct, here is Binding_key

Mandatory See reference 2

Immediate ibid.

Properties More property, how to set message persistence, see demo

Body Message body

amqp_rpc_reply_t amqp_channel_close (amqp_connection_state_t state,amqp_channel_t channel,int code);

amqp_rpc_reply_t amqp_connection_close (amqp_connection_state_t state,int code);

int amqp_destroy_connection (amqp_connection_state_t state);

How to consume the message, see demo after the text.

Demo

Https://github.com/liuhaobupt/rabbitmq_work_queues_demo-with-rabbit-c-client-lib

where rmq_new_task.c and rmq_worker.c correspond to work Queues chapters in RABBITMQ tutorial (http://www.rabbitmq.com/tutorials/ tutorial-two-python.html), emit_log_direct.c and receive_logs_direct.c correspond to tutorial chapters in the RABBITMQ routing (HTTP// www.rabbitmq.com/tutorials/tutorial-four-python.html), these two demos cover the common application scenarios of RABBITMQ.

Compiling requires LIBRABBITMQ.A libraries, as well as several header files (Amqp.h and amqp_framing.h) and UTILS.C files provided by Rabbitmq-c, which are available on the GitHub project page.

Reference documents

1. Rabbitmq-c Home Http://hg.rabbitmq.com/rabbitmq-c/summary

2. http://www.rabbitmq.com/amqp-0-9-1-reference.html

V. Recommended SITES

http://lostechies.com/derekgreer/tag/rabbitmq/

Http://www.rabbitmq.com/getstarted.html

(Chinese translation http://adamlu.net/dev/2011/09/rabbitmq-get-started/)

Http://alanxz.github.io/rabbitmq-c/docs/0.2/annotated.html

Https://github.com/liuhaobupt/rabbitmq_work_queues_demo-with-rabbit-c-client-lib

Six, simple code interpretation (omitted header file)

A Simple Consumer code demo is provided below, including most of the RABBITMQ processes

Implemented from the default switch, the queue named "QueueName1" in the acquisition of messages

int main (int argc, const char **argv) {

const char *hostname = "localhost"; Host Name

int port = 5672; Port

const char *exchange = ""; Switch is set to an empty string by default

const char *queuename = "QueueName1"; Queue name

amqp_socket_t *socket = NULL;

int sockfd;

int channelid = 1; The default open channel

amqp_connection_state_t Conn;

conn = Amqp_new_connection (); Create a new connection

Socket = AMQP_TCP_SOCKET_NEW (conn); Create a new socket

Die_on_error (sockfd = Amqp_socket_open (Socket,hostname, Port), "Opening socket"); Open socket

Die_on_amqp_error (Amqp_login (conn, "/", 0, 131072, 0, Amqp_sasl_method_plain, "Guest", "Guest"), "Logging in"); Logon server

Amqp_channel_open (conn, channelid); Open a channel

Die_on_amqp_error (Amqp_get_rpc_reply (conn), "Opening channel"); Ampq_get_rpc_reply is a function that clears certain global variables

Amqp_queue_declare (Conn,channelid,amqp_cstring_bytes (queuename), 0,1,0,0,amqp_empty_table); Declare a queue, and watch for parameter information against the API

Amqp_basic_qos (conn,channelid,0,1,0); Basic service processing, which can realize how much information is processed beforehand

Amqp_basic_consume (Conn,channelid,amqp_cstring_bytes (queuename), amqp_empty_bytes,0,1,0,amqp_empty_table); Start a queue consumption

Die_on_amqp_error (Amqp_get_rpc_reply (conn), "consuming");

{

while (1) {

amqp_rpc_reply_t Res;

amqp_envelope_t envelope;

Amqp_maybe_release_buffers (conn); Clear Cache

res = amqp_consume_message (conn, &envelope, NULL, 0); Give envelope the information you get.

if (amqp_response_normal! = Res.reply_type) {

Break

}

printf ("Delivery%u, Exchange%.*s routingkey%.*s\n",

(unsigned) Envelope.delivery_tag,

(int) Envelope.exchange.len, (char *) envelope.exchange.bytes,

(int) Envelope.routing_key.len, (char *) envelope.routing_key.bytes);

printf ("Content%.*s", (int) Envelope.message.body.len, (char *) envelope.message.body.bytes);

Amqp_destroy_envelope (&envelope);

}

}

Die_on_amqp_error (Amqp_channel_close (conn, 1, amqp_reply_success), "Closing channel"); Close Channel

Die_on_amqp_error (Amqp_connection_close (conn, amqp_reply_success), "Closing connection"); Close connection

Die_on_error (Amqp_destroy_connection (conn), "ending Connection"); Destroy connection

return 0;

}

Installation of local RABBITMQ services under 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.