Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup consumers that are no longer alive #230

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/main/java/org/swisspush/redisques/RedisQues.java
Original file line number Diff line number Diff line change
Expand Up @@ -816,13 +816,17 @@ private void gracefulStop(final Handler<Void> doneHandler) {
consumersMessageConsumer.unregister(event -> uidMessageConsumer.unregister(unregisterEvent -> {
if (event.failed()) log.warn("TODO error handling", exceptionFactory.newException(
"unregister(" + event + ") failed", event.cause()));
if (unregisterEvent.failed()) {
log.warn("TODO error handling", exceptionFactory.newException(
"unregisterConsumers() failed", unregisterEvent.cause()));
}
consumersAliveMessageConsumer.unregister(event1 -> {
if (event1.failed()) log.warn("TODO error handling", exceptionFactory.newException(
"unregister(" + event1 + ") failed", event1.cause()));
unregisterConsumers(false).onComplete(unregisterConsumersEvent -> {
if (unregisterEvent.failed()) {
if (unregisterConsumersEvent.failed()) {
log.warn("TODO error handling", exceptionFactory.newException(
"unregisterConsumers() failed", unregisterEvent.cause()));
"unregisterConsumers(false) failed", unregisterConsumersEvent.cause()));
}
stoppedHandler = doneHandler;
if (myQueues.keySet().isEmpty()) {
Expand Down Expand Up @@ -1200,16 +1204,21 @@ private Future<Void> notifyConsumer(final String queueName) {
log.debug("RedisQues Sending registration request for queue {}", queueName);
eb.send(configurationProvider.configuration().getAddress() + "-consumers", queueName);
promise.complete();
} else {
if (!aliveConsumers.containsKey(consumer)) {
log.warn("RedisQues consumer {} of queue {} does not exist.", consumer, queueName);
redisAPI.del(Collections.singletonList(key), event1 -> promise.complete());
} else {
// Notify the registered consumer
log.debug("RedisQues Notifying consumer {} to consume queue {}", consumer, queueName);
eb.send(consumer, queueName);
} else if (!aliveConsumers.containsKey(consumer)) {
log.warn("RedisQues consumer {} of queue {} does not exist.", consumer, queueName);
redisAPI.del(Collections.singletonList(key), result -> {
if (result.failed()) {
log.warn("Failed to removed consumer '{}'", key, exceptionFactory.newException(event.cause()));
ZhengXinCN marked this conversation as resolved.
Show resolved Hide resolved
} else {
log.debug("{} consumer key removed", result.result().toLong());
}
promise.complete();
}
});
} else {
// Notify the registered consumer
log.debug("RedisQues Notifying consumer {} to consume queue {}", consumer, queueName);
eb.send(consumer, queueName);
promise.complete();
}
}))
.onFailure(throwable -> {
Expand Down
Loading