-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
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:
Lines 69 to 80 in 619b24a
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); | |
} |
Lines 94 to 106 in 619b24a
@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.
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.