Spring Reactive Redis:PubSub不工作,如果发布者或订阅者不是在同一台机器上运行



我有两个spring引导服务在两个不同虚拟网络上的两个不同VM中运行。一个服务在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;
}

第二服务订阅上述频道以接收通知。

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();

}

如果发布者和订阅者都在同一台机器上运行,则上述设置可以正常工作。当我将发布者,即第一个服务移动到VM时;subscriberi.e.,第二服务已停止接收消息。

我可以从redis控制台看到,发布者确实在将消息推送到频道,但订阅者没有收到消息。

我可以确认,在所有场景中,发布者和订阅者都连接到同一个Azure Redis缓存实例。

虽然订户不收到消息是没有意义的,但我想知道,我这里缺少什么吗?频道在其运行的网络上有任何限制吗?

这并不完全是一个答案,但人们可能想知道Redis对待"mychannel";和mychannel作为两个不同的通道-一个带引号,另一个不带引号。

最新更新