Skip to content
Closed
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public abstract class AbstractDispatcherSingleActiveConsumer extends AbstractBas

protected boolean isFirstRead = true;
private static final int CONSUMER_CONSISTENT_HASH_REPLICAS = 100;
private int addConsumerFailedAttemptCount = 0;

public AbstractDispatcherSingleActiveConsumer(SubType subscriptionType, int partitionIndex,
String topicName, Subscription subscription,
Expand Down Expand Up @@ -176,7 +177,7 @@ public synchronized CompletableFuture<Void> addConsumer(Consumer consumer) {
return FutureUtil.failedFuture(new ConsumerBusyException("Exclusive consumer is already"
+ " connected"));
} else {
return addConsumer(consumer);
return internalAddConsumer(actConsumer, consumer);
}
});
} else {
Expand Down Expand Up @@ -225,6 +226,25 @@ public synchronized CompletableFuture<Void> addConsumer(Consumer consumer) {
return CompletableFuture.completedFuture(null);
}

/**
* This method is used to help debugging addConsumer failed for exclusive subscription.
* @param actConsumer
* @param consumer
* @return
*/
private synchronized CompletableFuture<Void> internalAddConsumer(Consumer actConsumer, Consumer consumer) {
addConsumerFailedAttemptCount++;
if (addConsumerFailedAttemptCount >= 5) {
log.warn("Added consumer failed with attempt count {}, consumers: {}, active consumer: {},"
+ "active state : {}",
addConsumerFailedAttemptCount, consumers, actConsumer, actConsumer.cnx().isActive());
addConsumerFailedAttemptCount = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add code to reset the counter also when the consumer has been successfully added

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a solution where the counter is passed as a parameter in the call stack would be more reliable?

return FutureUtil.failedFuture(new ConsumerBusyException("Exclusive consumer is already"
+ " connected"));
}
return addConsumer(consumer);
}

public synchronized void removeConsumer(Consumer consumer) throws BrokerServiceException {
log.info("Removing consumer {}", consumer);
if (!consumers.remove(consumer)) {
Expand Down
Loading