-
|
Is there a way to launch the SSE in lucky action? I saw there is a sse shard https://github.com/y2k2mt/sse.cr, following work. require "sse"
server = HTTP::Server.new [
HTTP::ServerSentEvents::Handler.new { |es, _|
es.source {
# Delivering event data every 1 second.
sleep 1
HTTP::ServerSentEvents::EventMessage.new(
data: ["foo", "bar"],
)
}
},
]
server.bind_tcp "127.0.0.1", 8080
server.listenHow to use it in lucky? Is there any sample lucky project can refer to? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
You can, but it's up to you to set it up. I did it once, but I don't have any examples laying around. Related One thing to keep in mind though is without using HTTP2 SSE is pretty useless. You're limited to something like 6 connections total with Crystal's HTTP server. That will change if we manage to get #1981 merged in |
Beta Was this translation helpful? Give feedback.
-
|
Somewhat relevant as I was exploring a similar thing for Athena. Depending on your exact use case, could consider using https://mercure.rocks/docs/mercure. The con is it requires another service running, but the benefit is that the lucky app no longer needs to also be the SSE server. It just has to make POST requests to the mercure hub which inherently does support HTTP/2, along with some other helpful abstractions like JWT auth and such. Also has the benefit of since the hub is centralized, could also emit SSE events via a CLI command or what have you. |
Beta Was this translation helpful? Give feedback.
You can, but it's up to you to set it up. I did it once, but I don't have any examples laying around. Related
One thing to keep in mind though is without using HTTP2 SSE is pretty useless. You're limited to something like 6 connections total with Crystal's HTTP server. That will change if we manage to get #1981 merged in