{{announcement.body}}
{{announcement.title}}

Redis-Based TransferQueue in Java

DZone 's Guide to

Redis-Based TransferQueue in Java

In this article, see an example of how to create an instance of an RTransferQueue object in Redisson.

· Database Zone ·
Free Resource

The TransferQueue interface in the Java programming language is a queue for passing messages according to the producer-consumer programming design pattern. The TransferQueue interface is based on the BlockingQueue interface in Java, with the additional stipulation that producers can wait until consumers receive their messages.

Redis is an open-source, in-memory data structure store that is often used to build distributed NoSQL key-value databases. Although many Java programmers would like to use Redis with Java, Redis is not automatically compatible with Java constructs such as TransferQueue out of the box.

For these reasons, many Java programmers install a Redis Java client such as Redisson in order to use TransferQueue in Redis.

You may also be interested in: Distributed Java Queues on Top of Redis

TransferQueues in Redis With Redisson

Redisson is a Redis Java client that implements many of the familiar objects and collections required for distributed applications in Java.

The TransferQueue interface in Java is reimplemented in Redisson with the RTransferQueue interface. Below is an example of how to create an instance of an RTransferQueue object:

Java


Once created, you can use the RTransferQueue to transfer a message from the producer:

Java


The corresponding method in the consumer’s thread or JVM is:

Java


or

Java


Redisson also includes implementations of TransferQueue using Async, Reactive, and RxJava2 interfaces.

Below is an example of TransferQueue in Redis using the Async interface:

Java


Below is an example of TransferQueue in Redis using the Reactive interface:

Java


Below is an example of TransferQueue in Redis using the RxJava2 interface:

Java


Thanks for reading!

Further Reading

Why Do We Need Thread.currentThread().interrupt() in Interruptible Methods?

Get Your Internal Queues Under Control in Java

Topics:
redis ,java ,queue ,database ,redis java client ,redisson

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}