Universal messaging and cache abstraction library for Java. Provides a simple, unified API for reading and writing byte messages to Apache Kafka, RabbitMQ, and Redis.
- ✅ Unified API - Single interface for all messaging systems
- ✅ 3 Systems - Apache Kafka, RabbitMQ, Redis
- ✅ Builder Pattern - Fluent, type-safe configuration
- ✅ Optional Dependencies - Include only the systems you need
- ✅ Thread-Safe - Concurrent operations supported
- ✅ AutoCloseable - Proper resource management
- ✅ Minimal Dependencies - Java 11+, system libraries are optional
<dependency>
<groupId>org.flossware</groupId>
<artifactId>jmessaging</artifactId>
<version>1.0</version>
</dependency>
<!-- Add system SDK (only include what you need) -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>4.3.0</version>
</dependency>import org.flossware.messaging.MessageClient;
import org.flossware.messaging.KafkaMessageClient;
// Create Kafka client
MessageClient client = KafkaMessageClient.builder()
.bootstrapServers("localhost:9092")
.topic("events")
.groupId("my-consumer-group")
.build();
// Write a message
client.write("user-123", "event data".getBytes());
// Read a message
byte[] data = client.read("user-123");
// Check if message exists
if (client.exists("user-123")) {
System.out.println("Message exists!");
}
// Clean up
client.close();MessageClient kafka = KafkaMessageClient.builder()
.bootstrapServers("localhost:9092")
.topic("events")
.groupId("consumer-group-1")
.pollTimeout(1000)
.build();Features:
- Producer and consumer in one client
- Internal message caching
- Configurable poll timeout
- Auto-generated group ID if not specified
Dependency:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>4.3.0</version>
</dependency>MessageClient rabbitmq = RabbitMqMessageClient.builder()
.host("localhost")
.port(5672)
.username("guest")
.password("guest")
.queuePrefix("msg.")
.build();Features:
- AMQP protocol
- Automatic queue creation
- Durable queues
- Virtual host support
Dependency:
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.30.0</version>
</dependency>MessageClient redis = RedisMessageClient.builder()
.host("localhost")
.port(6379)
.password("secret")
.database(0)
.keyPrefix("msg:")
.build();Features:
- Connection pooling (Jedis)
- Key prefix support
- Pattern-based key listing
- Database selection
Dependency:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>7.5.0</version>
</dependency>public interface MessageClient extends AutoCloseable {
void write(String key, byte[] value) throws IOException;
byte[] read(String key) throws IOException;
boolean exists(String key) throws IOException;
List<String> listKeys(String prefix) throws IOException; // Not supported by all
void delete(String key) throws IOException;
String getDescription();
void close() throws IOException;
}// Kafka for high-throughput event streaming
MessageClient events = KafkaMessageClient.builder()
.bootstrapServers("kafka.example.com:9092")
.topic("user-events")
.groupId("event-processor")
.build();
events.write("user-login", eventData);// RabbitMQ for reliable task queuing
MessageClient tasks = RabbitMqMessageClient.builder()
.host("rabbitmq.example.com")
.username("worker")
.password("secret")
.queuePrefix("tasks.")
.build();
tasks.write("email-queue", taskData);
byte[] task = tasks.read("email-queue");// Redis for high-speed caching
MessageClient cache = RedisMessageClient.builder()
.host("redis.example.com")
.keyPrefix("cache:")
.build();
cache.write("user-123", userData);
byte[] cached = cache.read("user-123");// Write to Kafka, cache in Redis
MessageClient kafka = KafkaMessageClient.builder()
.bootstrapServers("localhost:9092")
.topic("events")
.build();
MessageClient redis = RedisMessageClient.builder()
.host("localhost")
.keyPrefix("cache:")
.build();
byte[] data = "important event".getBytes();
kafka.write("event-1", data); // Persist to event stream
redis.write("event-1", data); // Cache for fast access| System | Speed | Durability | Use Case | Listing |
|---|---|---|---|---|
| Kafka | ⚡⚡⚡ | ⭐⭐⭐⭐⭐ | Event streaming, logs | ❌ No |
| RabbitMQ | ⚡⚡⚡⚡ | ⭐⭐⭐⭐ | Task queues, RPC | ❌ No* |
| Redis | ⚡⚡⚡⚡⚡ | ⭐⭐ | Caching, sessions | ✅ Yes |
*RabbitMQ listing requires Management HTTP API
-
Always use try-with-resources or close():
try (MessageClient client = builder.build()) { client.write("key", data); }
-
Use appropriate system for your use case:
// High-throughput events → Kafka // Reliable work queues → RabbitMQ // Fast caching → Redis
-
Handle null responses:
byte[] data = client.read("key"); if (data == null) { // Key not found or no messages available }
-
Use key prefixes to avoid collisions:
.keyPrefix("myapp:") // Redis .queuePrefix("myapp.") // RabbitMQ
This project uses X.Y semantic versioning (e.g., 1.0, 1.1, 2.0). Versions are automatically incremented on commits to the main branch and published to packagecloud.io.
<repositories>
<repository>
<id>packagecloud-flossware</id>
<url>https://packagecloud.io/flossware/java/maven2</url>
</repository>
</repositories>git clone https://github.com/FlossWare/jmessaging.git
cd jmessaging
mvn clean installApache License 2.0
- jcloudstorage - Cloud storage abstraction (S3, Azure, GCS, Google Drive, Dropbox, OneDrive)
- jfiletransfer - File transfer abstraction (SFTP, WebDAV, SMB/CIFS, FTP/FTPS)
- jcontainer - Container abstraction (Kubernetes, Docker, Hazelcast)
- jvcs - Version control abstraction (Git)
- jclassloader - Dynamic class loading from 34+ transport protocols