Avoid posting/consuming duplicate messages to/from RabbitMQ - c#

My requirement is not to consume the messages by the consumer if the condition not met, post the consumed message back to rabbitmq and stop the Masstransit bus (I believe consumer can't be stopped). I can post the consumed message back to rabbitmq and stop the bus but the problem is, as soon as I post the message back, my consumer consumes the same message again before stopping the bus and post the same message back again and it repeats until bus is stopped. In result, I'm getting duplicate messages on the queue.
if(!valid)
{
await ep.Send(message);
bus.StopAsync();
}
I think enabling rabbitmq_message_deduplication plugin may help in this situation but just wonder if there is any other ways to achieve.

Related

Sending and receiving information with Kafka

Is it possible to use kafka like api?
It means to send a message and wait to receive the answer.
I have just started programming with Kafka and I have a question about sending messages and receiving processing results.
Producers send events, and you can wait for an acknowledgement from the broker server, yes.
No, you cannot await receiving the consumer in the same action, because that is a separate Kafka function, and consumers poll from topics, rather than listen to the client-local producer events.

MassTransit/RabbitMQ How to get messages in the skipped queue and log this?

I am making an application in .NET6 in combination with MassTransit and RabbitMQ. Now I want to send messages to the skipped queue so that I can log it with Serilog.
I think I need to create a skipped queue consumer zo I can receive the messages. But I don't know how to send messages to the skipped queue so I can test it.
I already have a publisher and a consumer. But don't know how to send messages that are skipped.
Messages are moved to the _skipped queue due to developer/configuration errors, typically because the message type(s) are not consumed by the consumers on the receive endpoint connected to the original queue.
RabbitMQ has shovels which can be used to move those messages back into the original queue, there is no need to write a consumer for it since you'd likely end up with a _skipped_skipped queue.

rabbitmq what is difference between SubscribeAsync and PublishAsync in C#

I'm using rabbitmq in my microservices project and I saw these two methods
what are these and when do we use each
I suspect you're using something on top of RMQ, like EasyNetQ, because these aren't rabbit terms specifically, but in essence:
Publish publishes messages to a queue
Subscribe subscribes to a queue and defines the code that will act on the received message
A producer is a user application that sends messages while a consumer is a user application that receives messages.A queue is a buffer that stores those messages.
https://dev.to/mashaa/introduction-to-rabbitmq-49n8
In many pub/sub systems, publishers post messages to an intermediary message broker or event bus, and subscribers register subscriptions with that broker, letting the broker perform the filtering. The broker normally performs a store and forward function to route messages from publishers to subscribers. In addition, the broker may prioritize messages in a queue before routing.
https://en.m.wikipedia.org/wiki/Publish–subscribe_pattern
The core idea in the messaging model in RabbitMQ is that the producer never sends any messages directly to a queue. Actually, quite often the producer doesn’t even know if a message will be delivered to any queue at all.
https://www.rabbitmq.com/tutorials/tutorial-three-python.html

Send a response from consumer to producer RabbitMQ

I am using RabbitMQ to send data from a server to several consumers. I have to decide when a message will be deleted from the queue so I want to implement that the consumers send a message to the server. If all the consumers send a response then I will remove the message.
I already found an RPC call but I think that is to complex for the problem I have. Is there a faster way to send a quick response to the server? I am using C#.
UPDATE: I think I already found a solution. I will notify the broker so it can be removed from the queue.
You can use prefetch to send multiple messages. The prefetch value is used to specify how many messages that are being sent to the consumer at the same time.
The client can send an ack back to the server, which will delete the message from the broker.

MSMQ stop processing messages from queue

I am using MSMQ in WCF services. I am facing one issue in MSMQ, MSMQ stops processing messages from a queue after some time of intervals. I have to make a request to WCF service(.svc file) to start MSMQ. After requesting svc file MSMQ start processing messages from the queue.
I don't know exactly when MSMQ stop processing but, it stops after some time. Do I want to know why MSMQ goes in idle state? How can I resolve this issue?

Categories