Skip to content

Use separate logger for PulsarListener exceptions #1039

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

Merged
merged 1 commit into from
Feb 17, 2025
Merged
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 @@ -111,6 +111,9 @@ public class DefaultPulsarMessageListenerContainer<T> extends AbstractPulsarMess

private final Condition pausedCondition = this.lockOnPause.newCondition();

private final LogAccessor listenerErrorLogger = new LogAccessor(
"%s-ListenerErrors".formatted(DefaultPulsarMessageListenerContainer.class.getName()));

public DefaultPulsarMessageListenerContainer(PulsarConsumerFactory<? super T> pulsarConsumerFactory,
PulsarContainerProperties pulsarContainerProperties) {
super(pulsarConsumerFactory, pulsarContainerProperties);
Expand Down Expand Up @@ -629,7 +632,7 @@ else if (this.listener != null) {
inRetryMode.compareAndSet(true, false);
}
catch (RuntimeException e) {
DefaultPulsarMessageListenerContainer.this.logger.debug(e,
DefaultPulsarMessageListenerContainer.this.listenerErrorLogger.debug(e,
() -> "Error dispatching the message to the listener.");
if (this.pulsarConsumerErrorHandler != null) {
invokeRecordListenerErrorHandler(inRetryMode, message, e, txn);
Expand All @@ -642,9 +645,9 @@ else if (this.ackMode.equals(AckMode.BATCH)) {
this.nackableMessages.add(message.getMessageId());
}
else {
throw new IllegalStateException("Exception occurred and message %s was not auto-nacked; "
+ "switch to AckMode BATCH or RECORD to enable auto-nacks"
.formatted(message.getMessageId()),
throw new IllegalStateException(
"Exception occurred and message %".formatted(message.getMessageId())
+ "was not auto-nacked; switch to AckMode BATCH or RECORD to enable auto-nacks",
e);
}
}
Expand Down Expand Up @@ -713,6 +716,8 @@ private List<Message<T>> doInvokeBatchListener(Messages<T> messages, List<Messag
return Collections.emptyList();
}
catch (RuntimeException ex) {
DefaultPulsarMessageListenerContainer.this.listenerErrorLogger.debug(ex,
() -> "Error dispatching the messages to the batch listener.");
if (this.pulsarConsumerErrorHandler != null) {
return invokeBatchListenerErrorHandler(inRetryMode, messagesPendingInBatch, messageList, ex, txn);
}
Expand Down