In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "the basic concept of rabbitmq and the use of amqp-client". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Package com.rabbitmq.demo;import com.rabbitmq.client.*;public class Produce {public static void main (String args []) throws Exception {ConnectionFactory connectionFactory=new ConnectionFactory (); connectionFactory.setPassword ("guest"); connectionFactory.setPassword ("guest"); connectionFactory.setHost ("192.168.1.141"); connectionFactory.setPort (5672); Connection connection=connectionFactory.newConnection (); Channel channel= connection.createChannel () String exchangeName= "test"; String queueName= "test"; String routingkey= "routingkey"; String bindingkey=routingkey; / / set switch, direct connection, persistence, non-automatic deletion, parameter channel.exchangeDeclare (exchangeName, BuiltinExchangeType.FANOUT,true,false,null); / / channel.exchangeDeclare (exchangeName, BuiltinExchangeType.DIRECT,true,false,null) / * BuiltinExchangeType.FANOUT does not need to bind bindingkey and routingkey exchange to directly deliver messages to queue * BuiltinExchangeType.DIRECT needs to be bound and bindingkey is consistent with routingkey when exchange delivers messages to queue * BuiltinExchangeType.TOPIC requires binding fuzzy matching. The rules are as follows: * RoutingKey is a period "." A delimited string (by a period). " Each separate character, such as com.rabbit.demo,com.rabbit.test) * BindingKey RoutingKey, is also a period. Delimited strings; there can be two special strings "*" and "#" in * BindingKey for fuzzy matching, where "#" is used to match multiple (zero to multiple) and * to match any word. * if binding_key is "#"-it will receive all Message, no matter what routing_key is, just like fanout exchange. * if "*" and "#" is not used, then topic exchange becomes direct exchange. * BuiltinExchangeType.HEADERS does not need to be bound * Consumer arguments specifies "x-match". The Value of this key can be any or all, which indicates whether the Hash carried by the message needs to match all (all) or just one key (any). Persistence: the data will be saved to disk. Restart rabbitmq data still exists * * exclusive: the queue is only visible to the connection on which it was first declared and is automatically deleted when the connection is disconnected. * there are three points to note: the exclusive queue is visible based on the connection (Connection), and different channels (Channel) of the same connection * can access the exclusive queue created by the same connection at the same time. "first time" means that if a connection has declared an exclusive queue, other connections are not allowed to establish an exclusive queue with the same name, which is different from a normal queue: even if the queue * column is persistent, once the connection is closed or the client exits, the exclusive queue will be automatically deleted This queue * is suitable for application scenarios where a client sends and reads messages at the same time. * automatic deletion: sets whether to delete automatically. Set the queue column to be automatically deleted for true. The premise of automatic deletion is: * at least one consumer is connected to the queue, and then all consumers connected to the queue are disconnected. This parameter cannot be misinterpreted as: "when all clients connected to this queue are disconnected, the queue is automatically deleted" because the producer client creates the queue, or when there is no consumer client connected to the queue * column, the queue is not automatically deleted. * * according to business data, it is best to build exchange,queue and binding relationship in advance. Production side and consumer side can avoid many errors, such as exchang creation failure, * message delivery failure caused by uncertain binding relationship * * rabbitmq clinet property set * basic property set of props message, which contains 14 attribute members. There are contentType * content ncoding headers Map) deliveryMode priority * correlationld replyTo expiration messageld timestamp type userld * appld cluster. * * when the mandatory parameter is set to true, the switch cannot queue according to its own type and routing key. * the above situation occurs when RabbitM calls the Basic.Return command to return the message to the number of producers set to false. * then the message is directly discarded. How can the producer get the message that has not been correctly routed to the appropriate queue? At this time, channel addReturnListener will add the ReturnListener monitor implementation. * through the rabbitmq backup queue, when the message does not reach the main queue, it will be automatically sent to the backup queue. If the backup queue is set, the mandatory parameter will be invalid * / / set queue, persistence, non-exclusive, non-automatic deletion of channel.queueDeclare (queueName,true,false,false,null); / / channel.queueBind (queueName,exchangeName, bindingkey); for (int I = 0; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.