1: Required Jar: http://repo1.maven.org/maven2/com/rabbitmq/amqp-client/3.0.4/MAVEN configuration:Note: The version of the package is different, some classes cannot be found,Listed as: import Com.rabbitmq.client.QueueingConsumer;-----in version 5.0.0, in version 3.0.4, other versions need to be tested by themselves2: Create a Java project and directly introduce the following code test=======================
Maven DependencyDependency> groupId>Com.rabbitmqgroupId> Artifactid>Amqp-clientArtifactid> version>3.5.4version>Dependency>GitHubHttps://github.com/rabbitmq/rabbitmq-java-client/archives/masterDocumentHttp://www.rabbitmq.com/getstarted.htmlBasic Concept UnderstandingA producer a program, that sends messages.A queue is the name for a mailbox.A consumer is a pro
To test whether RABBITMQ is useful, a RABBITMQ basic functional test Case written in the Java language is written for informational purposes only.Code Description:Because the implementation language is Java, there are Java virtual machines (JDK or JRE installed) to test, no
declaring a durable queue (the queue will survive a server restart), which meets the requirements: We hope that after the server restarts, The unhandled message is still in the queue.
It should be noted that if the declared durable (true or false) is not allowed to change, the exception is reported, that is, once the queue in the server is created, this property cannot be changed.
Channel.queuedeclare (Task_queue_name, True, False, false, NULL);
"4" Parameter 3: Add Content-type to Text/plain a
Reference: http://www.rabbitmq.com/tutorials/tutorial-three-java.htmlPrerequisitesThis tutorial assumes that RABBITMQ on the standard port ( 5672) on the Local host installation and run . If you use a different host, port, or certificate, the connection settings need to be adjusted. in the previous tutorial, We have created a Task Force column. The assumption behind the work queue is that each task is delivered to only one consumer. In this
temporary queue where the client waits for the server to return information, and the server sends a message to this queue string replyqueuename =channel.queuedeclare (). Getqueue ();//generates a unique idfinal String Corrid = Uuid.randomuuid (). toString (); Amqp. Basicproperties props = NewAMQP.BasicProperties.Builder (). Correlationid (Corrid). RePlyto (Replyqueuename). build ();//client sends RFC request Channel.basicpublish ("", QueueName, props, "GetUserInfo". GetBytes ());// The server r
The Publish/Subscribe mode is where the producer sends the message to multiple consumers.Here are a few key concepts in the Publish/subscribe model-1. Exchanges (transponder)Maybe it turns out we're all sending and receiving messages based on a single queue. Now let's look at the complete message delivery pattern.The core concept of the RABBITMQ message pattern is: The producer does not send any messages directly to the queue . in fact, the producer
Example: implementation of RPC
This is an example of using RPC via AMQP, and RPC is a synchronous process that needs to wait for a response. In the actual application requires special messages, server may be slow performance, server may be shut down. Whether we must use RPC, or if we can replace it in an asynchronous way. Here, we are just demonstrating how to implement an RPC using the message management provided by RABBITMQ. The idea is as follows
Get ready:1. Download the RABBITMQ and build the environment (as in Python: http://www.cnblogs.com/g177w/p/8176797.html)2. Download the supported jar packages (http://repo1.maven.org/maven2/com/rabbitmq/amqp-client)Producer Side (Productor.java):1 Package rabbitmqtest;2 3 4 ImportJava.util.HashMap;5 ImportJava.util.Map;6 7 ImportCom.rabbitmq.client.AMQP.Queue;8 ImportCom.rabbitmq.client.Channel;9 Importcom.
RABBITMQ has four exchange types, namely direct, Fanout, Topic, HeadersExchange Features: fanoutDoes not process routing keys. You just need to simply bind the queue to the switch. A message sent to the type switch is broadcast to all queues that are bound to the switch. The following figure: TopicMatches a routing key to a pattern. The queue needs to be bound to a pattern at this time. The symbol "#" matches one or more words, and the symbol "*" can
middleware is mainly used for decoupling between components, the sender of the message does not need to know the existence of the message consumer, and vice versa. The main features of AMQP are message-oriented, queue, routing (including point-to-point and publish/subscribe), reliability, and security. RABBITMQ is an open-source AMQP implementation that is written in Erlang and supported by a variety of clients such as Python, Ruby,. NET,
supports most of the development languages you can think of, such as Java, Ruby, Python,. net, C/C ++, and Erlang. Clients in various languages can be downloaded from its official website. 2. Features of rabbitmq
Compared with other MQ products, rabbitmq has obvious advantages.
You can find some comparisons in the following links.
is sufficient. If you want a special setting, there are two ways:One is the environment variable configuration file rabbitmq-env.conf;A configuration file that is configuration information rabbitmq.config;Note that these two files are not by default and must be created yourself if necessary.Rabbitmq-env.confThe location of this file is deterministic and immutable, located in:/etc/rabbitmq directory (this d
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.