Configure the RabbitMQ service in Ubuntu 16.04

Source: Internet
Author: User
Tags rabbitmq amq

Configure the RabbitMQ service in Ubuntu 16.04

1. First, add the corresponding source

Under Ubuntu 16.04

Echo "deb https://dl.bintray.com/rabbitmq/debian xenial main" | sudo tee/etc/apt/sources. list. d/bintray. rabbitmq. list

Under Ubuntu 17.10

Echo "deb https://dl.bintray.com/rabbitmq/debian artful main" | sudo tee/etc/apt/sources. list. d/bintray. rabbitmq. list

2. Configure the Public Key

Wget-O-https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add-

3. Update and install the service

Sudo apt-get update

Sudo apt-get install rabbitmq-serve

After the installation is complete, it runs by default.

Invoke-rc.d rabbitmq-server stop/start // can run, the code is turned on or off

Enable Page Management

Rabbitmq-plugins enable rabbitmq_management

Run this code to access http: // localhost: 15672/for page management.

The above steps are complete after the RabbitMQ service is installed.

Introduction to some basic functions of RabbitMQ

1. Connection

// Connect to the service and obtain the handle
$ Connection = new AMQPStreamConnection ('localhost', 5672, 'Guest ', 'Guest ');
 
$ Connection-> isConnected () or die ("Cannot connect to the broker! \ N ");
 
$ Channel = $ connection-> channel ();

2. Definition

// Direct: in direct-type exchange, only the two routingkeys are identical, and exchange selects the corresponding binging for message routing.
// Fanout: This exchange routing rule routes messages directly to all bound queues without matching the message's routingkey.
// Topic: this type of exchange is similar to the direct type above. Here, the routingkey can have wildcards: '*', '#', where '*' indicates matching a word,
// '#' Indicates that no or multiple words are matched, and the key is matched in a pattern. For example, AB * can be passed to the queue of All AB *.
// Headers: not commonly used
$ Channel-> exchange_declare ('Demo', 'direct'); // declares a switch, which is equivalent to defining a rule.

// Passive: Negative processing. If a queue exists, it is returned. If no queue exists, PhpAmqpLib \ Exception \ AMQPProtocolChannelException is thrown directly.
// Durable: true, false true: Can survive when the server is restarted
// Exclusive: whether the queue is dedicated to the current connection. After the connection is disconnected, the queue is automatically deleted. This queue should be rarely used in the production environment.
// Autodelete: This queue is automatically deleted when no consumer is in use.
// Nowait: It is equivalent to an async declarative queue. It can be seen that no response is returned. The call method ends. Does not match the queue creation result
// Auto_delete: determines whether to automatically delete the queue when all consumer clients are disconnected.
// Arguments: additional parameters and rule settings
$ Channel-> queue_declare ('kzae ', false );

// Bind a queue to a vswitch
$ Channel-> queue_bind ('hello', 'amq. Direct', 'bbb ');

3. Send

// The mandatory flag tells the server to route the message to at least one queue; otherwise, the message is returned to the producer;
// Immediate indicates that the server immediately delivers the message to the queue associated with the message if there is a consumer. If no queue has a consumer,
// Directly return the message to the producer. You do not need to queue the message to wait for the consumer.
$ Channel-> basic_publish ($ msg, 'amq. Direct', 'bbb ');

4. Receive

// No-ack is used for confirmation. That is to say, after each Consumer receives the data, the RabbitMQ Server immediately marks the Message as complete and then deletes it from the Queue.
$ Channel-> basic_consume ('hello', '', false, $ callback );

5. Callback

$ Callback = function (PhpAmqpLib \ Message \ AMQPMessage $ msg ){
Echo "[x] Received", $ msg-> body, "\ n ";
 
// Delivery_info ['channel']: PhpAmqpLib \ channel \ AMQPChannel
Var_dump ($ msg-> delivery_info );
$ Msg-> delivery_info ['channel']-> basic_ack ($ msg-> delivery_info ['delivery _ tag']); // confirm ack
};

6. End

$ Channel-> close ();
$ Connection-> close ();

Setting up a RabbitMQ cluster in CentOS 7.2

Install and use professional message queue product RabbitMQ in CentOS7 Environment

RabbitMQ getting started

How to install RabbitMQ on CentOS7

How to Use NServiceBus with RabbitMQ

RabbitMQ cluster installation and configuration in CentOS 7

RabbitMQ practice: deploy distributed message queue in Chinese PDF

Detailed installation of RabbitMQ on CentOS7

RabbitMQ distributed cluster architecture and high availability (HA)

How to install and configure RabbitMQ in CentOS 7

RabbitMQ details: click here
RabbitMQ: click here

This article permanently updates link: https://www.bkjia.com/Linux/2018-02/151028.htm

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.