Redis Pub Sub does not work if the publisher and subscriber live in different networks.

Laguduva, Venkatesh 1 Reputation point
2020-11-09T11:18:27.733+00:00

I have two spring boot services running in two different VMs on two different virtual network.
One service runs on and pushes notifications to a channel in Azure RediscCache.

Optional<Long> hasMessageSent = redisStringTemplate.convertAndSend(syncQueue, GSON.toJson(data))
            .onErrorReturn(-1L).blockOptional(Duration.ofMinutes(BLOCK_MINUTES));
if (!hasMessageSent.isPresent() || hasMessageSent.get() < 0) {
   LOG.warn("Unable to send the sync message.");
   return false;
}

2nd service subscribes to the above channel to receive the notifications.

public void subscriberToChannel() {
    LOG.debug("Subscribing to channel " + syncQueue);

    redisTemplate.listenToChannel(syncQueue).name("SYNCQUEUER").doOnNext(msg -> {

    LOG.debug("New message received: '" + msg.toString());

    buildOrUpdateNotifications(getNotification(msg.getMessage()));

}).doOnError(e -> LOG.error("Error while listening at the channel, will continue.", e)).subscribe();

}

The above setup works fine if I have both publisher and subscriber run from the same machine.
When I moved the publisher i.e.,1st service to a VM; subscriberi.e., 2nd service has stopped receiving the messages.

I could see from the redis console that publisher is indeed pushing the messages to the channel but subscriber does not receive them.

I can confirm that in all the scenarios, publisher and subscribe are connected to the same Azure Redis Cache instance.

While it does not make sense for the subscriber not to receive the message, I am wondering, is there something I am missing here? does channel have any limitation on the network it is running on? I checked with 'CLIENT LIST' command; publisher lives at 20.x.x.x and subscriber at 183.x.x.x.

Azure Cache for Redis
Azure Cache for Redis
An Azure service that provides access to a secure, dedicated Redis cache, managed by Microsoft.
220 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Navtej Singh Saini 4,221 Reputation points Microsoft Employee
    2020-11-11T02:43:15.447+00:00

    @Laguduva, Venkatesh

    We have some confusion regarding the question. You are talking about VM and Azure Redis Cache. Are you using Redis on VM(IaaS) or both VM's connect to a Azure Redis Cache(PaaS). Please elaborate regarding the architecture for the same.

    Also we found this video which explains one of these scenario in detail. Please check if this can benefit you in any way. If not and you have further questions, Please briefly explain the architecture and get back to us and we will try to help you further.

    Regards
    Navtej S