First, the introduction of AMQP protocol

Feature 1: Distributed transaction support. 2: Support for message persistence. 3: High performance and highly reliable message processing advantages.

Distribution strategy: 1: Polling distribution 2: Fair distribution

AMQP message routing requires three parts: the switch, the route, and the binding

The consumer receives a message from the queue:

  1. Put the channel in receive mode through the AMQP basic.consume command until the queue subscription is unsubscribed. The ability to continuously receive messages
  2. Get a message to the queue via AMQP’s basic.get command implementation

Note:

  • RabbitMQ is based on the AMQP protocol
  • Two consumers share the same queue, the message consumption process cycle consumption, CoSumera, CoSumerb.

    1. When Messagea arrives in the queue, it is first sent to Conusumera and confirmed that it has received Messagea message in Consumera, and then RabbIMQ deletes Messagea from the queue


    2. Send message to Consumerb Ranhou….

  • Question 1: What will happen if Consumera doesn’t confirm the message?

    Messagea will send to the next consumer to ensure that the message is consumed. If Consumera does not confirm the message, the queue will not send the message to consumerA, which can be used to control the consumption time.

  • Question 2: What method is used to reject the message?

    Rabbitmq2.0.0 and above can use the AMQP basic.reject command. If RabbitMq2.0.0 and above use the AMQP command, reject it. Setting the requeue value of the reject command to true sends the message to the next message, and false removes the message.

Introduction to nouns:

  • producers
  • Payloads (actual transmitted data),
  • Tags (describing the data, specifying who can copy the message)
  • The queue
  • consumers
  • Channels: AMQP channels are created when a TCP connection is established. AMQP commands are sent over the channels, and each channel is assigned a unique ID.

Switch and bindings

The switch uses routing keys to distribute messages to different queues: there are 4 types of exchange direct, famous, topic, and headers(the headers exchange allows you to match the headers of AMQP messages instead of routing keys).

  1. Direct exchange: If the routing key matches, the message is delivered to the appropriate queue

The server must implement a direct type exchange, which contains a default exchange of a blank string. The name of the queue is the route key

  1. Famous exchange: Messages are matched to all queues attached to this exchange

3. Topic exchange: Messages are matched by wildcards so that messages from different sources arrive on the same queue

Three, virtual host

Each vhost is essentially a mini RabbitMQ server with its own queues, switches, and bindings. If an MQ is created in a RabbitMQ cluster, the vhost will be created in the entire cluster.

4. Message persistence and policies

  1. Set its Delicery Mode option to 2, send no persistent switches, and reach the persistent queue. The server writes persistent messages to the persistent log.

5. The general process of using RabbitMQ

  • Connect the Rabbitmq
  • Access channel
  • Declaration switch
  • Statement of the queue
  • Queue and exchange binding
  • News consumption
  • Close the channel
  • Close the connection

The RabbitMq is running on the Erlang 1, start node. / sbin/the RabbitMq server 2, close the node/sbin/rabbitmqctl stop only close the RabbitMq. / rabbitmqctl stop_app Rabbitmq_nodename. log (rabbitmq_nodename. log) rabbitmq_nodename. log (rabbitmq_nodename. log) rabbitmq_nodename. log (rabbitmq_nodename. log

The article reference book: “Rabbimq Efficient Deployment of Distributed Message Queuing”