Support Websocket feature
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!
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.
Is there any news on this?
Is there any news on this?
Not yet, sorry. If you would like to, I'm open to contributions.
Is anyone working on this? I'm interested in bringing this to life :)
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.
Is anyone working on this? I'm interested in bringing this to life :)
Nice :) THX for pushing it forward.
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?
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.
- [ ] Create new plugin with a channel scanner for web sockets annotations (
@MessageMapping,SendToand@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.
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.
-
In fact, if you only need websocket support, it is not particularly necessary to introduce
spring websocket, so the introduction ofspring websocketmust actually involve the use ofSTOMPandsock.js. -
I think citing Josh Long's explanation in
Sping Tipscan well understand the role ofspring websocketin this place, it appears to integrateSTOMPandsock.js(of coursesock.jsis 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 viaWebsocket.STOMPadds some headers, it has a unique area for payloads, so as long as both parties know about you WithSTOMP, you can communicate. Sincewebsocketitself has noheaders, 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.jsis a javascript library (refer to https://github.com/sockjs/sockjs-node ), which simulates websocket in the browser, even if the browser is not compatible withwebsocketAPI. 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 awebsocket-likeAPI be nice? Via a shim, if you allow you to mimic this behavior, it will work. On the browser side, applications can usesockjs-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 thesockjs-clientpage 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
STOMPandsock.js. Also forNodeJSthere 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 beforeSpringupdated 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.
Closing due to lack of activity. If someone is interested in contributing this, we will consider re-opening.
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?