This project is some experimentation with Redis Streams, mainly
setting up a producer that xadd
's to a stream and a consumer group
that...consumes...from the stream.
It's using lettuce, a comprehensive Java Redis client funded by Pivotal and providing three ways of interacting with the Redis API:
- Synchronous calls that block
- Asynchronous calls that returns Java Futures[1]
- Reactive Streams[2] from the Reactor[3] project (also from Pivotal)
Grab a very recent Redis 5.x version that supports streams. Install it and get it running locally just using the default settings for now.
This project was built using JDK 11, but should work with JDK 8.
Assuming you've got a recent JDK and javac in your path, this project uses Gradle for dependency and build management. The included wrapper script will download and bootstrap Gradle for you, so all you need is the JDK.
Simply execute the Gradle wrapper with the run
task:
$ ./gradlew run
Use
gradlew.bat
on Windows
You can run the producer ("ticker") or consumer ("taker") individually using gradle as well:
$./gradlew ticker
I've included a Gradle task for bundling up the project into an "uberjar" to make it easier to use without messing with Java classpaths.
$ ./gradlew shadowJar
$ ./java -jar ./build/libs/redisfun-0.1.0-SNAPSHOT-all.jar
The exposed entrypoints:
- main App:
io.sisu.redisfun.App
- producer:
io.sisu.redisfun.Ticker
- consumer:
io.sisu.redisfun.Taker
Which you can easily run via:
$ ./java -cp ./build/libs/redisfun-0.1.0-SNAPSHOT-all.jar \
io.sisu.redisfun.Ticker
Explore the following:
- stand-alone consumers that use reactor-style consumption models
- more complicated POJO storage...can I stick POJOs in the stream?
- compare with how this stream-based messaging approach would differ from a "brokerless" model like from zeromq
(These never render well in Github.)