Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
NotificationsYou must be signed in to change notification settings

ai-republic/http-sse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libraries for receiving and sending SSE (Server-Sent-Events). SSE producers and consumers can be defined via annotations. A standalone mode is also provided including SSL support.

Receiving SSE events

If you are using theBootstrap class all you need to do to receive SSE events is simply annotate a method with@SseConsumer and specify the event-source URI like the following:

@SseConsumer("https://some.server.com/sending/events")
public void consumeEvent(SseEvent sseEvent) {
...
}

Or

if you want to receiveSseEvents only using theSseService you can do this simply by calling:

sseService.receive(new URI("https://to.some.server"), sseEvent -> processTheEvent);

Producing SSE events

If you are using theBootstrap class all you need to do to produce SSE events is simply annotate a method with@SseProducer which must return aSseEvent like the following:

@SseProducer(path = "/sse/produce", maxTimes = -1, delay = 1, unit = TimeUnit.SECONDS)
public SseEvent produceEvent() {
  return new SseEvent.Builder().withData(words[counter++ % 4]).build();
}

This will start theSimpleServer to receive incoming requests, react on the configured URI path, perform the handshake and call the producer method according to the configured delay.

Or

if you implement your own server you can just register your producer class with theISseRegistry and call theSseService like the following:

sseService.processRequest(socketChannel, sslContext, sseRegistry);

Or

if you want to sendSseEvents to an openSocketChannel only using theSseService you can do this simply by calling:

sseService.handshake(socketChannel, sslEngine);
sseService.send(sseEvent, socketChannel, sslEngine);

SSL

To use SSL you only need to supply aSSLContext and/orSSLEngine. This can be easily created using theSslSupport class from thehttp-common library which is included as dependency with this project.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp