RABBITMQ Guide (Upper) _rabbit

Source: Internet
Author: User
Tags rabbitmq
Original source: Listen

RABBITMQ is a message-oriented middleware that uses RABBITMQ to fulfill our needs when scenarios such as asynchronous processing, publishing, and subscriptions are needed. The following is my study in the process of RABBITMQ some of the records, mainly translated from the RABBITMQ official website of the tutorials, coupled with some of my personal understanding. I will use three articles from RABBITMQ Hello World Introduction, to the final through the RABBITMQ RPC call, I believe that after reading these three articles you should be RABBITMQ basic concepts and use of a certain understanding.

Description: Because RABBITMQ supports the client of many languages, I am using the client of the Java language here. All the pictures are from RABBITMQ official website. Hello World

First need to install RABBITMQ, about the installation of RABBITMQ here is not to repeat, you can go to the official website of RABBITMQ to see the corresponding OS installation methods. When the installation is complete, use Rabbitmq-server to start RABBITMQ,RABBITMQ also provides a UI management interface, with the local default address localhost:15672, and the username and password as guest.

After the installation is complete, follow the usual practice of completing a simple Hello world example. The simplest kind of message-sending model is for a message sender (Producer) to send a message to the queue, and the message recipient (Consumer) in the other end accepts the message from the queue, as shown in the following figure:

First look at the code sent, a new class named Send.java, the first step of the code is to connect server 1 2 3 4 connectionfactory factory = new ConnectionFactory (); Factory.sethost ("localhost"); Connection Connection = Factory.newconnection (); Channel Channel = Connection.createchannel ();

Connection abstract socket connection, and for us to deal with the protocol version of the negotiations, authorization, and so on. Here we are connected to the local middleware, that is, localhost, next we create a channel, this is where most APIs complete the task, which means that our API operations are basically done through channel. 1 2 3 4 Channel.queuedeclare (Queue_name, False, False, false, NULL); String message = "Hello world!"; Channel.basicpublish ("", queue_name, NULL, message.getbytes ()); System.out.println ("[X] Sent '" + Message + "'");

The first is to declare a queue by channel, and declaring that the queue's operation is idempotent, which means that a new queue will be created only if the queue does not exist. This sends a Hello world! message with the actual message content being a byte array. 1 2 channel.close (); Connection.close ();

Finally, close the connection between channel and connection, and note that the order of closure is to close the channel connection first and then close the connection connection.

Complete Send.java Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14

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.