alanxz / rabbitmq-c

RabbitMQ C client
MIT License
1.76k stars 665 forks source link

Msg lost when consumer is set to no ack #741

Open 12doge-LEO opened 1 year ago

12doge-LEO commented 1 year ago

Hello,

Recently I found my rabbitmq client lost msgs when the network issue occured. The rabbitmq server log shows the msg was published and received at the same monent. Like:

2022-11-03 14:28:30:458: Message published 2022-11-03 14:28:30:458: Message received

After investigation, I found the consumer is inited with no_ack = true.

amqp_basic_consume(conn, 1, queuename, amqp_empty_bytes, 0, 1, 0, amqp_empty_table);

Can you please help me check if this no_ack config leads to the msg lost issue?

lesio999 commented 9 months ago

I think, I had the same issue,, where like more than 1 msg was pushed to the consumer and in case of issue at client multiple msgs were lost. That pushed me to implement amqp_basic_get(). But I'm looking at amqp_basic_consume again due to higher CPU utilization by basic_get in very tight loop. I would really like to hear about proper usage of amqp_basic_consume. is it possible to have only 1 message at the time and still use amqp_basic_consume?

reunanen commented 9 months ago

is it possible to have only 1 message at the time and still use amqp_basic_consume?

Have you tried setting prefetch_count to 1?

Maybe something along these lines?

amqp_basic_qos_t req;
req.prefetch_size = 0;
req.prefetch_count = 1;
req.global = false;

amqp_method_number_t method = AMQP_BASIC_QOS_METHOD;
amqp_method_number_t method_ok = AMQP_BASIC_QOS_OK_METHOD;

amqp_rpc_reply_t result = amqp_simple_rpc(conn, 1, method, &method_ok, &req);
lesio999 commented 9 months ago

I came across that setting using c# client in some other part of our system. will be trying it in c++ shortly.

thanks for response.

lesio999 commented 6 months ago

Something is still not right..

If/when I have 2 consumers and one is processing for long time, I would expect to all messages to be process by the other consumer and NOT to be queued to the first one (long runner). This is not what I see today, the messages are equally distributed to both consumers.

Is there any setup to prevent that behavior?

Leszek Lewicki Application Architect Sr O +1 908 994 3296 @.**@.> Cognizant.comhttp://www.cognizant.com/

From: Juha Reunanen @.> Sent: Saturday, December 2, 2023 5:12 AM To: alanxz/rabbitmq-c @.> Cc: Lewicki, Leszek (Cognizant) @.>; Comment @.> Subject: Re: [alanxz/rabbitmq-c] Msg lost when consumer is set to no ack (Issue #741)

CAUTION: External Email

is it possible to have only 1 message at the time and still use amqp_basic_consume?

Have you tried setting prefetch_count to 1?

Maybe something along these lines?

amqp_basic_qos_t req;

req.prefetch_size = 0;

req.prefetch_count = 1;

req.global = false;

amqp_method_number_t method = AMQP_BASIC_QOS_METHOD;

amqp_method_number_t method_ok = AMQP_BASIC_QOS_OK_METHOD;

amqp_rpc_reply_t result = amqp_simple_rpc(conn, 1, method, &method_ok, &req);

- Reply to this email directly, view it on GitHubhttps://github.com/alanxz/rabbitmq-c/issues/741#issuecomment-1837110623, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AUD5NH6K4I7VKOT5GCIVXDLYHL5HZAVCNFSM6AAAAAARWX6IIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZXGEYTANRSGM. You are receiving this because you commented.Message ID: @.***>

This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.

reunanen commented 6 months ago

Yeah, I would expect that too.

You may also try basic.get, instead of basic.consume. For more information, see e.g. this (just the first Google hit): https://www.cloudamqp.com/blog/rabbitmq-basic-consume-vs-rabbitmq-basic-get.html

Yes I know that using basic.get is generally discouraged.

lesio999 commented 6 months ago

I'm already using basic.get but it is putting stress on rabbit server with constant pinging. The consume is much faster and lighter on server but not happy with distribution across consumers

Leszek Lewicki Application Architect Sr O +1 908 994 3296 @.**@.> Cognizant.comhttp://www.cognizant.com/

From: Juha Reunanen @.> Sent: Friday, February 16, 2024 9:49 AM To: alanxz/rabbitmq-c @.> Cc: Lewicki, Leszek (Cognizant) @.>; Comment @.> Subject: Re: [alanxz/rabbitmq-c] Msg lost when consumer is set to no ack (Issue #741)

CAUTION: External Email

Yeah, I would expect that too.

You may also try basic.get, instead of basic.consume. For more information, see e.g. this (just the first Google hit): https://www.cloudamqp.com/blog/rabbitmq-basic-consume-vs-rabbitmq-basic-get.html

Yes I know that using basic.get is generally discouraged.

- Reply to this email directly, view it on GitHubhttps://github.com/alanxz/rabbitmq-c/issues/741#issuecomment-1948520921, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AUD5NHZ3ZAJ6KXD4LGMQ5H3YT5WUNAVCNFSM6AAAAAARWX6IIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBYGUZDAOJSGE. You are receiving this because you commented.Message ID: @.***>

This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.