Description: ahead of the local environment and online environment are ok, only the testing environment will appear the condition of the missing information,
Details: using messaging rabbitmqTemplate, initialization configuration when the CachingConnectionFactory
SetPublisherConfirms (true), setPublisherReturns (true), setChannelCacheSize (100), setChannelCheckoutTimeout (600), and
SimpleRabbitListenerContainerFactory setPrefetchCount (100), setConcurrentConsumers (10), setAcknowledgeMode (AcknowledgeMode. MANUAL), these are some producers confirmed that the callback mode configuration, consumer confirm model configuration and channel, the channel configuration, the number of messages in the rest of the default configuration,
Then the message is sent to the rabbitmq, producers receive confirm confirmation, return is an ack=true, and there is no trigger returnMessage callback, explains the message is sent to the rabbitmq really exchange, and were found to match the queue (local test when unbind queue, indeed trigger returnMessage callback), but can be seen from the consumer logs, each time will be lost, it's worth noting that each project, launched the first message loss probability is very big, of course, resend this message ok,
Ask for advice,
Code:
Producers
Public void sendMsg (String content) {
CorrelationData correlationId=new CorrelationData (UUID. RandomUUID (), toString ());
Logger. The info (" the rabbitMq send MSG: {} ", content);
RabbitTemplate. ConvertAndSend (" exchange ", "routingKey", the content, correlationId);
}
@ Override
Public void confirm (CorrelationData CorrelationData, Boolean ack, String cause) {
Logger. The info (" callback data: {}, ack: {}, cause: {} ", correlationData, ack, cause);
If (ack) {
Logger. The info (" news consumption success ");
} else {
Logger. Warn (" news consumption failed: "+ cause);
//omit resend code...
}
}
@ Override
Public void returnedMessage (Message Message, int replyCode, String replyText, String exchange, String routingKey) {
Logger. Warn (" the message is missing, will send again, : exchange ({}), the route ({}), replyCode ({}), replyText ({}), message: {} ", exchange, routingKey, replyCode, replyText, message);
//omit resend code...
}
Consumer:
@ RabbitListener (the queues="queue", containerFactory="simpleRabbitListenerContainerFactory")
Public class RabbitMqReceiver {
@ RabbitHandler
Public void process (String content, @ Headers Map
Logger. The info (" the rabbitMq received MSG: {} ", content);
Long deliveryTag=(Long) headers. Get (AmqpHeaders. DELIVERY_TAG);
Channel. BasicAck (deliveryTag, false);
//omit business code...
}
}
CodePudding user response:
Mend tracing log{" timestamp ":" the 2020-10-21 2:03:45:689 ", "type" : "published", "node" : "rabbit @ BackupServer", "connection" : "127.0.0.1:54098 - & gt; 127.0.0.1:5672","vhost":"/","user":"guest","channel":12,"exchange":"exchange","queue":"none","routed_queues":["queue"],"routing_keys":["routingKey"],"properties":{"priority":0,"delivery_mode":2,"headers":{"spring_returned_message_correlation":"8ea40148-7b31-4e7f-a39d-e5f94cea8ae4","spring_listener_return_correlation":"2e76a86a-7024-4fd0-8b3a-5a69825c3a96"},"content_encoding":"UTF-8","content_type":"text/plain"},"payload":"eyJ0YXNrSWQiOiIxNGJjZGM0My01Y2YzLTRkZjYtOTBlOC0wYmNjM2ZkOTgyZmQiLCJ1cmwiOiIvZGF0YS93ZWIvcHJvamVjdC9tZmsveWlucGluL3JlY29yZF95aW5waW4vMzgzNC82LndhdiJ9"}
{" timestamp ":" the 2020-10-21 2:03:45:689 ", "type" : "received", "node" : "rabbit @ BackupServer", "connection" : "127.0.0.1:54098 - & gt; 127.0.0.1:5672","vhost":"/","user":"guest","channel":2,"exchange":"exchange","queue":"queue","routed_queues":"none","routing_keys":["routingKey"],"properties":{"priority":0,"delivery_mode":2,"headers":{"spring_returned_message_correlation":"8ea40148-7b31-4e7f-a39d-e5f94cea8ae4","spring_listener_return_correlation":"2e76a86a-7024-4fd0-8b3a-5a69825c3a96"},"content_encoding":"UTF-8","content_type":"text/plain"},"payload":"eyJ0YXNrSWQiOiIxNGJjZGM0My01Y2YzLTRkZjYtOTBlOC0wYmNjM2ZkOTgyZmQiLCJ1cmwiOiIvZGF0YS93ZWIvcHJvamVjdC9tZmsveWlucGluL3JlY29yZF95aW5waW4vMzgzNC82LndhdiJ9"}
CodePudding user response:
I send only 7 news, tracing the log with all the sent messages, but only some consumer log sent messages, and tracing and no new message, that message has not been the end of the line, and see the rabbitmq console, you can see no unacked message, the message should be discarded, and then how to deal with,,,CodePudding user response:
Refer to the following message loss solutions.https://www.jianshu.com/p/19e0927315da
CodePudding user response:
You look at your message log on the rabbitmq server, each message are the way of the log recorded in the fileCodePudding user response: