Fix PollableChannels for Micrometer
* Add Micrometer metrics capture for the `PollableAmqpChannel` and `PollableJmsChannel` * Polishing and optimization for the `AbstractPollableChannel.receive()` **Cherry-pick to 5.0.x**
This commit is contained in:
committed by
Gary Russell
parent
6934690947
commit
35daaae632
@@ -22,11 +22,11 @@ import java.util.List;
|
||||
|
||||
import org.springframework.integration.support.management.CounterFacade;
|
||||
import org.springframework.integration.support.management.PollableChannelManagement;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.ExecutorChannelInterceptor;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Base class for all pollable channels.
|
||||
@@ -95,7 +95,7 @@ public abstract class AbstractPollableChannel extends AbstractMessageChannel
|
||||
boolean counted = false;
|
||||
boolean countsEnabled = isCountsEnabled();
|
||||
try {
|
||||
if (logger.isTraceEnabled()) {
|
||||
if (isLoggingEnabled() && logger.isTraceEnabled()) {
|
||||
logger.trace("preReceive on channel '" + this + "'");
|
||||
}
|
||||
if (interceptorList.getSize() > 0) {
|
||||
@@ -105,21 +105,28 @@ public abstract class AbstractPollableChannel extends AbstractMessageChannel
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Message<?> message = this.doReceive(timeout);
|
||||
if (countsEnabled && message != null) {
|
||||
if (getMetricsCaptor() != null) {
|
||||
incrementReceiveCounter();
|
||||
Message<?> message = doReceive(timeout);
|
||||
if (message == null) {
|
||||
if (isLoggingEnabled() && logger.isTraceEnabled()) {
|
||||
logger.trace("postReceive on channel '" + this + "', message is null");
|
||||
}
|
||||
getMetrics().afterReceive();
|
||||
counted = true;
|
||||
}
|
||||
if (message != null && logger.isDebugEnabled()) {
|
||||
logger.debug("postReceive on channel '" + this + "', message: " + message);
|
||||
else {
|
||||
if (countsEnabled) {
|
||||
if (getMetricsCaptor() != null) {
|
||||
incrementReceiveCounter();
|
||||
}
|
||||
getMetrics().afterReceive();
|
||||
counted = true;
|
||||
}
|
||||
|
||||
if (isLoggingEnabled() && logger.isDebugEnabled()) {
|
||||
logger.debug("postReceive on channel '" + this + "', message: " + message);
|
||||
}
|
||||
|
||||
}
|
||||
else if (logger.isTraceEnabled()) {
|
||||
logger.trace("postReceive on channel '" + this + "', message is null");
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(interceptorStack)) {
|
||||
|
||||
if (interceptorStack != null) {
|
||||
message = interceptorList.postReceive(message, this);
|
||||
interceptorList.afterReceiveCompletion(message, this, null, interceptorStack);
|
||||
}
|
||||
@@ -139,7 +146,7 @@ public abstract class AbstractPollableChannel extends AbstractMessageChannel
|
||||
}
|
||||
getMetrics().afterError();
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(interceptorStack)) {
|
||||
if (interceptorStack != null) {
|
||||
interceptorList.afterReceiveCompletion(null, this, e, interceptorStack);
|
||||
}
|
||||
throw e;
|
||||
@@ -214,10 +221,10 @@ public abstract class AbstractPollableChannel extends AbstractMessageChannel
|
||||
* return immediately with or without success). A negative timeout value
|
||||
* indicates that the method should block until either a message is
|
||||
* available or the blocking thread is interrupted.
|
||||
*
|
||||
* @param timeout The timeout.
|
||||
* @return The message, or null.
|
||||
*/
|
||||
@Nullable
|
||||
protected abstract Message<?> doReceive(long timeout);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user