springwolf-core icon indicating copy to clipboard operation
springwolf-core copied to clipboard

Support Websocket feature

Open vladigeras opened this issue 5 years ago • 13 comments

Hi! Thank you for project! I want to know, can i use it for documenting Spring Websocket functionality?

For example I use next configuration:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
	@Override
	public void configureMessageBroker(MessageBrokerRegistry config) {
		config.enableSimpleBroker("/topic", "/queue");
	}

	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) {
		registry
				.addEndpoint("/custom-endpoint")
				.setAllowedOrigins("*")
				.withSockJS();
	}
}

And next controller method:

@MessageMapping("/custom-path")
@SendToUser("/queue/custom-path")
public CustomModelResponse getStops(@Payload(required = false) CustomFilter filter) {

	// business logic invocation
        return ...
}

Can I describe it with your project to generate documentation and show it in Swagger like format (like Swagger for REST) and give it to client application? I guess, request, response models and url path will be show inside. Thank you!

vladigeras avatar Jul 15 '20 07:07 vladigeras

Thanks for the suggestion! Asyncapi specification supports websockets and it looks like enough information can be gathered automatically from the annotations, so this is absolutely doable.

So while springwolf does not support websockets at the moment, definitely expect it in a future version. Also if would like to contribute, we can discuss and design a solution to support it together.

stavshamir avatar Jul 15 '20 07:07 stavshamir

Is there any news on this?

pixelstuermer avatar Nov 30 '20 15:11 pixelstuermer

Is there any news on this?

Not yet, sorry. If you would like to, I'm open to contributions.

stavshamir avatar Dec 10 '20 10:12 stavshamir

Is anyone working on this? I'm interested in bringing this to life :)

VeggieTeriyaki avatar Aug 26 '21 13:08 VeggieTeriyaki

That would be great! Work and Covid took most of my available time to contribute to this project. Let me know if you need guidance or help if you eventually choose to implement this.

stavshamir avatar Aug 28 '21 04:08 stavshamir

Is anyone working on this? I'm interested in bringing this to life :)

Nice :) THX for pushing it forward.

pixelstuermer avatar Aug 31 '21 11:08 pixelstuermer

Is anyone working on this? I'm interested in bringing this to life :)

I'm happy to see this issue move forward. Is there any progress on this issue?

linghengqian avatar Dec 05 '21 18:12 linghengqian

Is anyone working on this? I'm interested in bringing this to life :)

I'm happy to see this issue move forward. Is there any progress on this issue?

Not yet. Looks like it could be useful though so I'll try tackling this in the close future hopefully.

stavshamir avatar Dec 07 '21 08:12 stavshamir

  • [ ] Create new plugin with a channel scanner for web sockets annotations (@MessageMapping, SendTo and @SendToUser)
  • [ ] Create an example project
  • [ ] @linghengqian We should discuss the name of the plugin - eventhough this is actually STOMP, if the spring dependency, package and classes use the websockets terminology it might be confusing to use a different name here

Another issue is how to implement a springwolf publisher for STOMP like the other plugins have.

In general, I never worked with websockets, so I will appreciate corrections in terminology and code review.

stavshamir avatar May 05 '22 17:05 stavshamir

I'm a step ahead of you a bit. We can use my drafted Plugin PR for reference.

So everything AsyncAPI touches is based on Websockets. HTTP is purely Call-Response (Albeit you can do HTTP-Streams, but that's a separate Topic), where as Websockets allow for Server-Side Events to get pushed to the Client.

STOMP is just like AMQP in that they're just protocols for dictating how the data should get transferred over the Websocket Connection. So stomp-plugin is the correct name, since Spring is expecting (and sending) STOMP frames over the connection.

Crain-32 avatar May 05 '22 17:05 Crain-32

  • In fact, if you only need websocket support, it is not particularly necessary to introduce spring websocket, so the introduction of spring websocket must actually involve the use of STOMP and sock.js.

  • I think citing Josh Long's explanation in Sping Tips can well understand the role of spring websocket in this place, it appears to integrate STOMP and sock.js (of course sock.js is not a mandatory choice, it is also related to what we are going to discuss irrelevant).

    • Stomp (see https://stomp.github.io/ ) can be used to communicate payloads back and forth from Client to Service via Websocket. STOMP adds some headers, it has a unique area for payloads, so as long as both parties know about you With STOMP, you can communicate. Since websocket itself has no headers, this is a problem if you want to propagate additional information, such as security tokens and the like that are not added to the websocket protocol.

    • sock.js is a javascript library (refer to https://github.com/sockjs/sockjs-node ), which simulates websocket in the browser, even if the browser is not compatible with websocket API. So in theory, you could have an application that degrades gracefully on older browsers , 2022 now we have websocket support naturally, you can count on it being compatible in almost all browsers, but just in case, know that you can still get one Wouldn't a websocket-like API be nice? Via a shim, if you allow you to mimic this behavior, it will work. On the browser side, applications can use sockjs-client . It emulates the W3C WebSocket API and communicates with the server to choose the best transport option, depending on the browser running it. See the sockjs-client page and the list of transport types supported by browsers. The client also provides several configuration options - for example, specifying which transports to include.

  • spring websocket itself provides clients for STOMP and sock.js. Also for NodeJS there are https://github.com/sockjs/sockjs-client/ and https://github.com/jmesnil/stomp-websocket (this library has long since stopped updating, but used its validation before Spring updated its documentation Is it a good choice. Refer to https://docs.spring.io/spring-framework/docs/6.0.0-M3/reference/html/web.html#websocket-stomp-enable )

  • update in 2022.05.18 : After a long struggle with a Discord customer on the mailing list, I finally unblocked my Discord account and confirmed the channel messages.

linghengqian avatar May 05 '22 23:05 linghengqian

Closing due to lack of activity. If someone is interested in contributing this, we will consider re-opening.

stavshamir avatar May 23 '23 04:05 stavshamir

Since we have AsyncAPI support for both STOMP and Websocket, maybe we can take a simple approach providing a simple springwolf-websocket-binding annotation support, like we are now doing for sns or sqs.

WDYT?

ctasada avatar Apr 15 '24 17:04 ctasada