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

Fix websocket autoconfig startup failure caused by Spring Messaging 5.3.2 #315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -22,7 +22,7 @@
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.ChannelInterceptorAdapter;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.messaging.support.ExecutorChannelInterceptor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
Expand All @@ -32,8 +32,7 @@
* This class implements a {@link ExecutorChannelInterceptor} to instrument the websocket
* communications using an OpenTracing Tracer.
*/
public class TracingChannelInterceptor extends ChannelInterceptorAdapter implements
ExecutorChannelInterceptor {
public class TracingChannelInterceptor implements ChannelInterceptor, ExecutorChannelInterceptor {

/**
* The span component tag value.
Expand Down Expand Up @@ -66,8 +65,8 @@ public class TracingChannelInterceptor extends ChannelInterceptorAdapter impleme
*/
protected static final String OPENTRACING_SCOPE = "opentracing.scope";

private Tracer tracer;
private String spanKind;
private final Tracer tracer;
private final String spanKind;

public TracingChannelInterceptor(Tracer tracer, String spanKind) {
this.tracer = tracer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.support.AbstractMessageChannel;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport;

Expand All @@ -37,22 +38,22 @@ public class WebsocketAutoConfiguration {
private Tracer tracer;

@Bean
@ConditionalOnBean(WebSocketMessageBrokerConfigurationSupport.class)
@ConditionalOnBean(value = AbstractMessageChannel.class, name = "clientInboundChannel")
public TracingChannelInterceptor tracingInboundChannelInterceptor(
WebSocketMessageBrokerConfigurationSupport config) {
AbstractMessageChannel clientInboundChannel) {
TracingChannelInterceptor interceptor = new TracingChannelInterceptor(tracer,
Tags.SPAN_KIND_SERVER);
config.clientInboundChannel().addInterceptor(interceptor);
clientInboundChannel.addInterceptor(interceptor);
return interceptor;
}

@Bean
@ConditionalOnBean(WebSocketMessageBrokerConfigurationSupport.class)
@ConditionalOnBean(value = AbstractMessageChannel.class, name = "clientOutboundChannel")
public TracingChannelInterceptor tracingOutboundChannelInterceptor(
WebSocketMessageBrokerConfigurationSupport config) {
AbstractMessageChannel clientOutboundChannel) {
TracingChannelInterceptor interceptor = new TracingChannelInterceptor(tracer,
Tags.SPAN_KIND_CLIENT);
config.clientOutboundChannel().addInterceptor(interceptor);
clientOutboundChannel.addInterceptor(interceptor);
return interceptor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
@EnableAutoConfiguration
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
Expand All @@ -36,4 +36,4 @@ public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/test-websocket").withSockJS();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
Expand All @@ -40,7 +40,7 @@ public class WebsocketTest {
@Configuration
@EnableWebSocketMessageBroker
@EnableAutoConfiguration
public static class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
public static class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Bean
public Tracer tracer() {
Expand Down