在 Spring Boot 中无法解锁 Rabbit Listener 中的 Redisson 锁

问题描述 投票:0回答:1

我在 Spring Boot 的 rbbit 监听器中有以下代码块。我尝试使用 redisson 获取锁:

@RabbitListener(queues = Const.Rabbit.QUEUE_NAME, concurrency = "1")
    public void consumer(byte[] payload) throws IOException {
        String lockName = "lock-name";
        RLock lock = redissonClient.getLock(lockName);
        try {
            // call a method
        } catch (Exception e) {
            log.error("error: {}", e.getMessage());
        } finally {
            lock.unlock();
        }
    }

然后我收到以下错误。它无法释放锁,因为它没有被当前线程锁定。接下来,因为兔子消息没有得到确认。兔子无限地重新传递它。

org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Listener method 'public void consumer(byte[]) throws java.io.IOException' threw exception
.
.
.
Caused by: java.lang.IllegalMonitorStateException: attempt to unlock lock, not locked by current thread by node id: e8289934-2820-42f2-aa3d-30c3f56ce1ac thread-id: 100
java spring-boot spring-amqp redisson
1个回答
0
投票

根据您分享的代码片段,之前必须有此代码

try

lock.lock();

请参阅 Redisson 文档中的更多信息:https://github.com/redisson/redisson/wiki/8.-Distributed-locks-and-synchronizers

© www.soinside.com 2019 - 2024. All rights reserved.