订阅已取消订阅

时间:2018-09-20 11:48:07

标签: spring redis

有时,当我尝试建立pubsub连接时,会收到错误消息:“订阅已取消订阅,无法再使用。”​​

为了解决该问题,我需要重新启动Web应用程序。

public GideResponse getResponsePubSub(long petitionId, GidePetitionList<GideBackendPetition> petitionList) {
    CountDownLatch latch = new CountDownLatch(1);
    GideResponseReceiver receiver = new GideResponseReceiver(latch);
    MessageListenerAdapter adapter = new MessageListenerAdapter(receiver);
    this.container.addMessageListener(adapter, new PatternTopic(String.valueOf(petitionId)));
    this.redisTemplateBackend.opsForList().rightPush(PETITIONS_QUEUE_NAME, petitionList);
    latch = receiver.getLatch();

    try {
        latch.await(40000L, TimeUnit.MILLISECONDS);
    } catch (InterruptedException var8) {
        logger.error("The countdown latch for redis pub sub was interrupted", var8);
        var8.printStackTrace();
        throw new InternalCommunicationException();
    }

    if(latch.getCount() == 1L) {
        logger.error("The pub sub request has not been processed, message was not received");
        this.container.removeMessageListener(adapter);
        throw new InternalCommunicationException();
    } else {
        this.container.removeMessageListener(adapter);
        return receiver.getGideResponse();
    }
}

spring-data-redis库中是否有任何方法可以解决此类问题?

我正在使用'org.springframework.data:spring-data-redis:1.8.9.RELEASE'

0 个答案:

没有答案