Last week I introduced RabbitMQ streams and how you could produce and consume streams through the RabbitMQ.Stream.Client in .NET. Yesterday I showed how you can improve and simplify producing messages by using a Reliable Producer. Today I want to introduce its counterpart on the consumer side; the Reliable Consumer.
Introducing Reliable Consumers
Reliable Consumers builts on top of Consumer
and adds the following features:
- Auto-Reconnect in case of disconnection
- Auto restart consuming from the last offset
- Handle the metadata Update
Auto-Reconnect
The Reliable Consumer will try to restore the TCP connection when the consumer is disconnected for some reason.
Auto restart consuming from the last offset
The Reliable Consumer will restart consuming from the last offset stored. So you don’t have to store and query the last offset yourself.
Handle the metadata update
If the streams topology changes (ex:Stream deleted or add/remove follower), the client receives an MetadataUpdate
event. The Reliable Consumer detects this event and tries to reconnect the consumer if the stream still exist or closes the consumer when the stream is deleted.
Receiving messages through the Reliable Consumer
Receiving messages through the Reliable Consumer happens in the same way as with the default Consumer.