Skip to content

SimpMessagingTemplate.convertAndSend results in UnsupportedOperationException when Spring Cloud Sleuth is present #25821

@rogue2yjg

Description

@rogue2yjg

springboot version: 2.1.3
spring-websocket version: 5.1.1
spring-cloud-sleuth version: 2.1.1

When I try to use SimpMessagingTemplate.convertAndSend to send a String message to the websocket client after adding spring cloud sleuth to the application, an exception occurs:

Caused by: java.lang.UnsupportedOperationException: null
	at java.util.Collections$UnmodifiableMap.remove(Collections.java:1460)
	at org.springframework.messaging.support.NativeMessageHeaderAccessor.removeNativeHeader(NativeMessageHeaderAccessor.java:209)
	at org.springframework.cloud.sleuth.instrument.messaging.MessageHeaderPropagation.removeAnyTraceHeaders(MessageHeaderPropagation.java:86)
	at org.springframework.cloud.sleuth.instrument.messaging.TracingChannelInterceptor.preSend(TracingChannelInterceptor.java:173)
	at org.springframework.messaging.support.AbstractMessageChannel$ChannelInterceptorChain.applyPreSend(AbstractMessageChannel.java:178)
	at org.springframework.messaging.support.AbstractMessageChannel.send(AbstractMessageChannel.java:132)
	... 123 common frames omitted

some primary code belows:

@RequestMapping(value = "/ws/reply", method = RequestMethod.GET)
public String msgReply(@RequestParam String msg) {
	System.out.println(msg);
	template.convertAndSend("/riten_ws_topic", msg);
	return msg;
}
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
	@Override
	public void configureMessageBroker(MessageBrokerRegistry config) {
		config.enableSimpleBroker("/riten_ws_topic");
		config.setApplicationDestinationPrefixes("/riten_ws_client");
	}
	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) {
		registry.addEndpoint("/riten_ws_server").setAllowedOrigins("*").withSockJS();
	}
}

Metadata

Metadata

Assignees

Labels

in: messagingIssues in messaging modules (jms, messaging)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions