RabbitMQ (2), rabbitmq

Source: Internet
Author: User
Tags rabbitmq

RabbitMQ (2), rabbitmq

The last time RabbitMQ was installed and vhost and user were successfully created, but the production and consumption processes were not completed yet. This time, we called this process.

The main problem last time was that the Process Code was not compiled and saved, which is actually a Python program. In the past two days, I have read the basic knowledge of Python and completed it.

Basic production and consumption of Hello World:

1. Production send. py:

Go to vim and compile the production process.


!/usr/bin/env pythonimport pikaconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))channel = connection.channel()channel.queue_declare(queue='hello')channel.basic_publish(exchange='',routing_key='hello',body='Hello World!')print " [x] Sent 'Hello World!'"connection.close()

Process: first establish a connection with the RabbitMQ server. localhost indicates the local host. If you want to connect to another host, use the corresponding host address.

Declare the queue hello; because the message cannot be directly transmitted to the message queue, an exchange is required. The default exchange is used here.

'', Routing_key is the queue name, and then close the connection.


2. Consume receive. py

Go to vim and write the consumption process.

!/usr/bin/env pythonimport pikaconnection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))channel = connection.channel()channel.queue_declare(queue='hello')print ' [*] Waiting for messages. To exit press CTRL+C'def callback(ch, method, properties, body):    print " [x] Received %r" % (body,)channel.basic_consume(callback,queue='hello',no_ack=True)channel.start_consuming()

Process: establish a connection; declare a queue. The reason for this statement is that we do not know what the pre-existing queue is, so we determine our goals.

The consumption queue is the queue hello in send. py, which we abbreviated earlier. Then, we establish our consumption method callback, and then declare the consumption

The object queue is a hello queue and then started.


During the test, start the production process send. py:

$ python send.py [x] Sent 'Hello World!'

Then we will display the production ID message: [x] Sent 'Hello World! '

The production process stops every execution.

Then start the consumption process:


$ python receive.py [*] Waiting for messages. To exit press CTRL+C [x] Received 'Hello World!'

Here we will find the message 'Hello World! ', So that a production consumption is completed.

Payment process.

You can also open two terminals and execute the production process on one of them. We will find that our consumption ID is always displayed on the other terminal.

Information, that is, consumption while producing.


The second part is the consumption of multiple worker .....












How to configure multiple RabbitMQ instances on one machine

There are three configuration files for Rabbitmq, which are located at/etc/rabbitmq/. The three files are: (1) enabled_plugins. Set the list of allowed plug-ins, the configuration file is in the List format of erlang, such as [rabbitmq_management, rabbitmq_visualiser]. (2) rabbitmq. conf, set the operation parameters of rabbitmq. Each parameter in this configuration file is a tuple of erlang. The structure is {Key, Value}, Key is of the atom type, and Value is a term. The key parameters are: tcp_listerners sets the listening port of rabbimq. The default value is [5672]. Disk_free_limit: low watermark of a disk. If the disk capacity is lower than the specified value, the system stops receiving data. The default value is {mem_relative, 1.0}, which is associated with the memory and can be customized. vm_memory_high_watermark: Set the low-level memory line. If it is lower than this level line, the traffic control mechanism is enabled. The default value is 0.4, that is, 40% of the total memory. Hipe_compile uses High Performance Erlang compiler to compile some rabbimq code to improve Performance. This parameter is experimental. If erlang vm segfaults appears, disable it.

Rabbitmq_java_client322 why is an error reported when importing data to eclipse?

It may be that the jar package in the project does not have the build path. You can right-click the project and select java build path under properties.
Import the jar package in the project

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.