Skip to content

Default WebSocketMessageBrokerConfigurer is always overriding custom channel executor #42924

@shmyer

Description

@shmyer

When using Spring Websocket with Spring Boot, the latter provides a WebSocketMessagingAutoConfiguration which provides a default WebSocketMessageBrokerConfigurer which sets either the single task executor found in the context or the executor named "applicationTaskExecutor" for the inbound and outbound client channels:

WebSocketMessageConverterConfiguration(ObjectMapper objectMapper,
Map<String, AsyncTaskExecutor> taskExecutors) {
this.objectMapper = objectMapper;
this.executor = determineAsyncTaskExecutor(taskExecutors);
}
private static AsyncTaskExecutor determineAsyncTaskExecutor(Map<String, AsyncTaskExecutor> taskExecutors) {
if (taskExecutors.size() == 1) {
return taskExecutors.values().iterator().next();
}
return taskExecutors.get(TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME);
}

@Override
public void configureClientInboundChannel(ChannelRegistration registration) {
if (this.executor != null) {
registration.executor(this.executor);
}
}
@Override
public void configureClientOutboundChannel(ChannelRegistration registration) {
if (this.executor != null) {
registration.executor(this.executor);
}
}

When trying to set a custom executor for my inbound and outbound channels in my custom WebSocketMessageBrokerConfigurer implementation, it doesn't have any effect. The issue seems to be, that in DelegatingWebSocketMessageBrokerConfiguration the list of configurers always (at least in my case), processes the default configurer provided by Spring Boot after my custom one, causing my executor configuration to be overridden with the default one.

https://github.com/spring-projects/spring-framework/blob/c2c6bb25c68c231e8eb250809442987512755d62/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.java#L49-L54

Debugging shows the order:
image

https://github.com/spring-projects/spring-framework/blob/c2c6bb25c68c231e8eb250809442987512755d62/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.java#L71-L83

Instead, the DelegatingWebSocketMessageBrokerConfiguration should probably always process the default implementation first and then any custom configurers, probably via looking at @Order annotations. Now I don't know if that is an issue which must be handled in Spring Boot or in Spring Framework, but I can raise the issue in the latter project if you feel like it should be handled there.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions