I have an exercise about Redis Pubsub like the following:
In case the publisher publish a message but the subscriber has not received the server has crashed. How to subscriber receive that message when restart server?.
Please help me, thank you !
In this case, the message is gone forever.
Redis only has limited support for PUBSUB scenario. Besides your case, if the connection between Redis and the client is lost, the client will also lose all published messages.
If you need more reliable PUBSUB tools, you should try other stuffs, e.g. Kafka, RabbitMQ.
Related
I read the official document of Rabbitmq, it is not really clear for me what was that?
its something like Consumer Ack but with a difference that the Publisher Confirm is send by rabbitmq server to Publisher client when the server get the message from publisher client?
Can someone explain more about it?
thanks in advance.
its something like Consumer Ack but with a difference that the
Publisher Confirm is send by rabbitmq server to Publisher client when
the server get the message from publisher client?
Yes. When you enable publisher confirms, and your publisher receives acknowledgement that the message is published, you can be certain of it.
Without publisher confirms, you can lose messages in several cases. One example: your application could publish the data to the TCP buffer, but then crash, or the server itself could crash. Another example: a network device could fail mid-delivery. Another example: RabbitMQ itself could crash after receiving the TCP data containing your message.
NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.
I am working on redis SMQ persistence. My questions here is, While publisher publishing the messages, consumer has stopped suddenly. When consumer connects again, is it possible to subscribe messages from where it has stopped?
No - Redis' Pub/Sub has no persistence, and once a message has been published, it is sent only to the connected subscribed clients. Afterwards, the message is gone forever.
With standard Pub/Sub you can use Lua scripts to persist your message. You need to check whether you have a listener on channel or not. If not then storing your message with channel key on redis . When the subscriber cames back it checks if there is anything for him based on channel key. Second option is to use Redis Stream. Check this gist.
Plz use 2 redis connections: 1 pubsub, second - LPOP/RPOP
The idea is:
I have N WCF services which connected and subscribed to the same Redis message channel. These services use this channel to exchange messages to sync some caches and other data.
How each service can ignore its own messages? I.e. how to publish to all but me?
It looks like Redis PUB/SUB doesn't support such filtration. So, the solution is to use set of individual channels for every publisher and common channel for subscription synchronization between them. Here is an golang example of no-echo chat application.
I have experienced the following situation with an ActiveMQ Pub/Sub implementation. If the connection to the message broker is lost the publisher could re-try to establish a connection since the publish method would throw an exception.
However if the connection to the message broker is lost at the subscriber end, the subscriber would not know it. This would be the same if the session expires.
Proposed solution:
One of the solutions I thought was to implement a heartbeat at the subscriber end to periodically publish a ping message to a separate topic so that the subscriber could know if the connection is dropped. This works fine, but the down side is that the amount of ping messages generated by the subscribers available in the system. The second option I thought was to implement the heartbeat to try and create a connection in an interval. WDYT?
Do you see a better way of implementing this? Appreciate your thoughts.
Use the ActiveMQ Failover transport and don't disable the inactivity monitor and the client will check the connection and automatically reconnect as needed. Without more information on you set-up that's about the best answer.
I went thought NServiceBus documentation including the durable messaging one. What I understand is that when the server is offline the messages continue to go into the server's input queue which get picked up when server comes back online.
But what if the server is completely down and the input queue is not accessible?
I'm using Bus.Send from the client.
It depends on what transport you're using.
In the case of a brokered message queue, like Azure Service Bus, as long as that service is available, the fact the machine that will eventually retrieve the messages is offline is irrelevant, as that machine is simply asking the external queuing service for messages. The same goes for a transport like SQL Server.
In the case of a transport like MSMQ, which is a store a forward style queue, the messages will remain in a local outgoing queue until the remote machine becomes available.
Can you double check that you are looking in the correct spot? If you aren't getting an error out of NServiceBus when you Send, then MSMQ is installed. If it can't be reached or the service is stopped you should get errors.
The Outbound queues are in a different place as illustrated here:
http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-components-postattachments/00-09-06-31-16/outgoingempty.JPG
As RMD indicated, this is an advantage of the store and forward MSMQ transport.. the local outbound queue should just stack these up until the remote server is available.
Thx.
Joe