JetStream Publishing with the NATS.io Java Library

The previous entry, JetStream Stream Creation with the NATS.io Java Library in this series showed us how to create a stream. Once you have defined a stream, you can publish to the configured subjects. Publishing to stream subjects isn't really much different from publishing a regular NatsMessage. Once a subject is established, you could publish a regular NatsMessage to that subject, but there are benefits to publishing via the JetStream API instead of the regular message API.

Publish Acknowledgement

When you publish via the JetStream API, each publishes will receive an acknowledgment or PublishAck. This is the server's way of letting you know it has received the message and has handled it according to the options like storage, retention, and replication that were established when creating the stream.

NATS.io JetStream Stream Creation With the NATS Java Library

The NATS Java library with support for JetStream has just been released!

JetStream allows you to persist streams of messages, allows consumers to either subscribe in real-time or to access the messages at a later time with the added flexibility to choose from where in the stream you want to start receiving messages. You can start reading from the stream at a specific point in time or start at a specific message sequence number.