As you may have seen, I have joined Redis Labs a month ago; one of the first task as a new hire is to learn more about Redis. So I learned, and I am still learning.
This is when I discovered Redis Streams. I am a big fan of streaming-based applications so it is natural that I start with a small blog post explaining how to use Redis Streams and Java.
What is Redis Streams?
Redis Streams is a Redis Data Type, that represents a log so you can add new information/message in an append-only mode (this is not 100% accurate since you can remove messages from the log). Using Redis Streams you can build "Kafka Like" applications, what I mean by that you can:
- create applications that publish and consume messages (nothing extraordinary here, you could already do that with Redis Pub/Sub)
- consume messages that are published even when your client application (consumer) is not running. This is a big difference with Redis Pub/Sub
- consume messages starting a specific offset, for example, read the whole history, or only new messages
In addition to this, Redis Streams has the concept of Consumer Groups. Redis Streams Consumer Groups, like Apache Kafka ones, allows the client applications to consume messages in a distributed fashion (multiple clients), providing an easy way to scale and create highly available systems.
Enroll in the Redis University: Redis Streams to learn more and get certified.
Sample Application
The redis-streams-101-java GitHub Repository contains sample code that shows how to
- post messages to a streams
- consume messages using a consumer group