com.ai-republic:http-sse-test

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.

License

License

GroupId

GroupId

com.ai-republic
ArtifactId

ArtifactId

http-sse-test
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

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.

Download http-sse-test

How to add to project

<!-- https://jarcasting.com/artifacts/com.ai-republic/http-sse-test/ -->
<dependency>
    <groupId>com.ai-republic</groupId>
    <artifactId>http-sse-test</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.ai-republic/http-sse-test/
implementation 'com.ai-republic:http-sse-test:1.0.1'
// https://jarcasting.com/artifacts/com.ai-republic/http-sse-test/
implementation ("com.ai-republic:http-sse-test:1.0.1")
'com.ai-republic:http-sse-test:jar:1.0.1'
<dependency org="com.ai-republic" name="http-sse-test" rev="1.0.1">
  <artifact name="http-sse-test" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.ai-republic', module='http-sse-test', version='1.0.1')
)
libraryDependencies += "com.ai-republic" % "http-sse-test" % "1.0.1"
[com.ai-republic/http-sse-test "1.0.1"]

Dependencies

compile (7)

Group / Artifact Type Version
com.ai-republic : http-sse-impl jar 1.0.1
com.ai-republic : http-sse-se jar 1.0.1
org.junit.platform : junit-platform-engine jar 1.5.0-RC1
org.junit.platform : junit-platform-commons jar 1.5.0-RC1
jakarta.enterprise : jakarta.enterprise.cdi-api jar 2.0.1
org.glassfish.hk2.external : jakarta.inject jar 2.6.0
jakarta.annotation : jakarta.annotation-api jar 1.3.4

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.4.2
org.junit.jupiter : junit-jupiter-engine jar 5.4.2

Project Modules

There are no modules declared in this project.

HTTP SSE

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 the Bootstrap 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 receive SseEvents only using the SseService you can do this simply by calling:

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

Producing SSE events

If you are using the Bootstrap class all you need to do to produce SSE events is simply annotate a method with @SseProducer which must return a SseEvent 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 the SimpleServer 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 the ISseRegistry and call the SseService like the following:

sseService.processRequest(socketChannel, sslContext, sseRegistry);

Or

if you want to send SseEvents to an open SocketChannel only using the SseService 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 a SSLContext and/or SSLEngine. This can be easily created using the SslSupport class from the http-common library which is included as dependency with this project.

Versions

Version
1.0.1
1.0.0