Thanks to visit codestin.com
Credit goes to github.com

Skip to content

WebSocket support with @EnableWebFlux #22587

Description

@joshlong

It seems like I almost never need to do anything with WebSocketHandlerAdapter when using WebFlux and websockets. I just need to register it, like this:

@Bean
SimpleUrlHandlerMapping simpleUrlHandlerMapping(WebSocketHandler wsh) {
	return new SimpleUrlHandlerMapping() {
		{
			setUrlMap(Map.of("/ws/time", wsh));
			setOrder(10);
		}
	};
}

@Bean
WebSocketHandlerAdapter wsha() {
	return new WebSocketHandlerAdapter();
}

@Bean
WebSocketHandler wsh(Timer timer) {
	return session -> session.send(timer.greet().share().map(session::textMessage));
}

I can see why i need to register the WebSocketHandler (that's where my custom websocket logic lives) and I can see why I need to register the SimpleUrlHandlermapping bean (that's where my custom routing lives). But why the WebSocketHandlerAdapter? Could it be auto-configuration registered based on the presence of websockets on the classpath and subject to a @ConditionalOnMissingBean so that users who want to contribute their own can do so? it seems ceremonial.

thanks in advance..

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions