PHP RabbitMQ message properties

Sending a message can specify some parameters for the message

  • Delivery mode: Whether to persist, 1-Non-persistent, 2-Persistent
  • Headers:Headers can have any name. Only long string headers can be set here.
  • Properties: You can set other message properties here (delivery mode and headers are pulled out as the most common cases). Invalid properties will be ignored. Valid properties are: 
  1. content_type: the type of message content
  2. content_encoding: the encoding format of the message content
  3. priority: the priority of the message
  4. correlation_id: correlation id
  5. reply_to: The name of the queue used to specify the reply
  6. expiration: the expiration time of the message
  7. message_id: message id
  8. timestamp: the timestamp of the message
  9. type: Type
  10. user_id: user id
  11. app_id: application id
  12. cluster_id: cluster id
  13. Payload: message content

E.g:

Add message_id when producing a message:

$message = new AMQPMessage($messageBody, ['content_type' => 'text/plain','message_id'=>123, 'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT]); // 定义消息

When consuming news:

if($msg->has('message_id')){
    echo_txt(' >>> message_id '. $msg->get('message_id'). "\n");
}

 

Guess you like

Origin blog.csdn.net/yyws2039725/article/details/113916308