Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websockets support? #147

Open
Mechite opened this issue Jan 22, 2023 · 2 comments
Open

Websockets support? #147

Mechite opened this issue Jan 22, 2023 · 2 comments

Comments

@Mechite
Copy link
Contributor

Mechite commented Jan 22, 2023

Could we see some kind of websocket support here or in a seperate avaje-sockets library? It would be nice to be able to have a Spring-like system for them too, in a glimpse I see this guide from Spring with the following sample:

(...)
@Controller
public class GreetingController {

  @MessageMapping("/hello")
  @SendTo("/topic/greetings")
  public Greeting greeting(HelloMessage message) throws Exception {
    Thread.sleep(1000); // simulated delay
    return new Greeting("Hello, " + HtmlUtils.htmlEscape(message.getName()) + "!");
  }
}

This controller is concise and simple, but plenty is going on. We break it down step by step.

The @MessageMapping annotation ensures that, if a message is sent to the /hello destination, the greeting() method is called.

The payload of the message is bound to a HelloMessage object, which is passed into greeting().

Internally, the implementation of the method simulates a processing delay by causing the thread to sleep for one second. This is to demonstrate that, after the client sends a message, the server can take as long as it needs to asynchronously process the message. The client can continue with whatever work it needs to do without waiting for the response.

After the one-second delay, the greeting() method creates a Greeting object and returns it. The return value is broadcast to all subscribers of /topic/greetings, as specified in the @SendTo annotation. Note that the name from the input message is sanitized, since, in this case, it will be echoed back and re-rendered in the browser DOM on the client side.

This is a pretty beautiful system, but obviously as all things Spring is bloated and obnoxious, and Javalin (and Heildon actually, I've personally zero experience with Heildon so I'm probably stating things you're already aware of) already provides support for websockets.
Javalin has websocket registration right inside of ApiBuilder and I imagine Heildon has a simple system to do so as well, so it shouldn't be too much work to get this to work.

@rbygrave
Copy link
Contributor

Could we see some kind of websocket support here

Yes. The plan is to add support for Websockets. We haven't done it to date because A) haven't hit the need personally plus B) Nima Websockets support is still WIP and it's good to have 2 implementations to target.

My thought was to also support SSE (Server Sent Events) but I need to look at the details there. Javalin has SSE but I need to check that in Helidon.

@re-thc
Copy link
Contributor

re-thc commented Sep 22, 2024

Can we revisit? Has Helidon added enough features to support this? I see a lot of SSE and Websocket features now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants