NATS Blog

Welcome to the NATS Blog! We have content from NATS Maintainers, end-users, and community contributors. We always appreciate outside contributions so if you would like to contribute a blog post, see our Contributor's Guide for more information.

NATS Java Client Latency Benchmarking

SCOTT FAUERBACH — June 21, 2021

NATS Java Client Latency Benchmarking Many users have asked to see how the NATS Java client performs specifically in regard to latency. This blog will discuss using the NatsAutoBench program to run a latency test and how to generate a CSV file that can be used to make a histogram. The NatsAutoBench can run a variety of tests. This blog will focus only on the latency testing. Running the Latency Test You can run the latency test from an IDE or a command line, but you will need to build from the source code. Read more...

JetStream Pull Consumers with the NATS.io Java Library

SCOTT FAUERBACH — June 8, 2021

JetStream Pull Consumers with the NATS.io Java Library The last entry in this series talked about push consumers . This entry will demonstrate the basics of a pull subscription. Pull A pull subscription allows you to control when the server sends the client messages. There is one API method call used for creating a pull subscription: JetStreamSubscription subscribe(String subject, PullSubscribeOptions options) throws IOException, JetStreamApiException; subject - every subscription needs a subject options - configure PullSubscribeOptions or use the default configuration PullSubscribeOptions The PullSubscribeOptions allows you to identify the stream name and is a helper for the most common pull ConsumerConfiguration option, the durable name. Read more...

JetStream Push Consumers with the NATS.io Java Library

SCOTT FAUERBACH — June 3, 2021

JetStream Push Consumers with the NATS.io Java Library The last entry in this series talked about the consumer options that are available when subscribing to messages. This entry will demonstrate the basics of a push subscription. Push A push subscription is where the server is in control and sends messages to the client. It can be made durable or ephemeral based on your use case. Here are the API method calls used for creating a push subscription: Read more...

Synchronous and Asynchronous Publishing with the NATS.io Java Library

SCOTT FAUERBACH — May 27, 2021

Synchronous and Asynchronous Publishing with the NATS Java Library In the continuation of the series on using the NATS Java client with JetStream , there is new video that demonstrates publishing messages to a stream synchronously and asynchronously. Check out this video: The source code discussed in the video can be found here: PublishAsync PublishSync.java About the Author Scott Fauerbach is a member of the engineering team at Synadia Communications . Read more...

JetStream Consumers with the NATS.io Java Library

SCOTT FAUERBACH — May 21, 2021

The previous entries in this series showed us how to create JetStream streams and publish messages. This entry will start building up to subscribing by describing the configuration for consumers. Push vs Pull Subscription Consumers, once created, can subscribe as either a push or pull mode. The server sends messages to push consumers while pull consumers have to ask for messages. This is mentioned here first because consumer configuration options may apply differently depending on the type of subscription. Read more...

Replace your MQTT broker with NATS Server

IVAN KOZLOVIC — May 20, 2021

Replace your MQTT broker with NATS Server v2.2.0+ NATS Server v2.2.0+ has native support for MQTT v3.1.1 protocol. If you already have a deployment with existing MQTT broker(s) and use NATS messaging, or are planning to, this blog post will show you how easy it is to replace your existing MQTT broker with a NATS server. Not only you would have to manage a single server instead of two, using NATS with MQTT will allow you to exchange data from MQTT to NATS and vice-versa. Read more...

Java client usage on Android with Kotlin

IVÁN FERRO — May 15, 2021

Java Client Usage on Android with Kotlin Dependencies To use the official NATS.java library in Android we need to add the dependency to the build.gradle file at Module level. Please use the latest released version, which at this writing is 2.11.2 dependencies { //other dependencies implementation 'io.nats:jnats:2.11.2' } Implementation We will create a class as a manager to control our NATS client to be able to connect, disconnect, publish … This is necessary because when nats. Read more...

NATS Java Client JetStream Multi Tool

SCOTT FAUERBACH — May 13, 2021

As we were building the NATS Java client we realized we wanted code to run the client through its paces. We built unit tests, example code and added basic functionality to our existing benchmarking tool. As we talked to prospective users, they were asking for benchmarks across the variety of different ways we can publish and subscribe. For instance see publishing synchronous versus asynchronous. Push versus pull consuming. Different amounts of threading with shared or individual connections to the server. Read more...

Pub-Sub with NATS CLI

R.I. PIENAAR — May 11, 2021

Publish-Subscribe with NATS CLI Previously we introduced the New NATS CLI , today we look at the Publish-Subscribe pattern using the CLI. Links to related documentation: Subjects-Based Messaging Publish-Subscribe Queue Subscriptions Request-Reply The NATS CLI About the Author R.I. Pienaar is a long-time NATS Maintainer and a senior member of the engineering team at Synadia Communications . Read more...

Hello World with the NATS.io Java Library

SCOTT FAUERBACH — May 5, 2021

Hello World with the NATS Java Library Recently, stream functionality was added to the NATS server in release 2.2. See our JetStream section in docs for additional information. Check out this video where I discuss the basics of how to create a stream and then publish and consume messages using the NATS Java client . The full source of the project can be found here: https://github.com/nats-io/java-nats-examples/tree/main/hello-world About the Author Scott Fauerbach is a member of the engineering team at Synadia Communications . Read more...