Ignoring the special Stream DirectChannel which is not a DirectChannel; fixes gh-1155

This commit is contained in:
Marcin Grzejszczak
2019-01-07 16:46:43 +01:00
parent 2579e7887d
commit 88ba09467c

View File

@@ -81,6 +81,8 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
*/
private static final String REMOTE_SERVICE_NAME = "broker";
public static final String STREAM_DIRECT_CHANNEL = "org.springframework.cloud.stream.messaging.DirectWithAttributesChannel";
final Tracing tracing;
final Tracer tracer;
@@ -95,6 +97,9 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
private final boolean hasDirectChannelClass;
// special case of a Stream
private final Class<?> directWithAttributesChannelClass;
@Autowired
TracingChannelInterceptor(Tracing tracing) {
this(tracing, MessageHeaderPropagation.INSTANCE,
@@ -113,6 +118,9 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
"org.springframework.integration.context.IntegrationObjectSupport", null);
this.hasDirectChannelClass = ClassUtils
.isPresent("org.springframework.integration.channel.DirectChannel", null);
this.directWithAttributesChannelClass = ClassUtils
.isPresent(STREAM_DIRECT_CHANNEL, null)
? ClassUtils.resolveClassName(STREAM_DIRECT_CHANNEL, null) : null;
}
public static TracingChannelInterceptor create(Tracing tracing) {
@@ -195,8 +203,20 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
}
private boolean isDirectChannel(MessageChannel channel) {
return this.hasDirectChannelClass
&& DirectChannel.class.isAssignableFrom(AopUtils.getTargetClass(channel));
Class<?> targetClass = AopUtils.getTargetClass(channel);
boolean directChannel = this.hasDirectChannelClass
&& DirectChannel.class.isAssignableFrom(targetClass);
if (!directChannel) {
return false;
}
if (this.directWithAttributesChannelClass == null) {
return true;
}
return !isStreamSpecialDirectChannel(targetClass);
}
private boolean isStreamSpecialDirectChannel(Class<?> targetClass) {
return this.directWithAttributesChannelClass.isAssignableFrom(targetClass);
}
@Override