This library provides a Java interface for interacting with PGMQ, a message queue system built on top of PostgreSQL.
pgmq-client accomplishes most of primitive features of pgmq, including:
- Creating or deleting queues
- Sending messages
- Reading and batch reading in normal or long polling mode
- Archiving messages
- Deleting and popping messages
... and so on
Here are some examples of how to use the library.
PGMQueueFactory pgmqFactory = new PGMQueueFactory(jsonSerializer, connectionProvider);
PGMQueue pgmq = pgmqFactory.create();
pgmq.create("my_queue");
// Send and read a message test
TestMessage testMessage = new TestMessage("test", Instant.now().getEpochSecond());
pgmq.send("my_queue", testMessage);
Optional<TestMessage> message = pgmq.read("my_queue")
.as(TestMessage.class)
.visibilityTime(30)
.oneValue();
// Send multiple messages and read values
List<TestMessage> messages = Stream.generate(() -> new TestMessage("test", Instant.now().getEpochSecond()))
.limit(10)
.toList();
pgmq.sendBatch(queueName, messages);
pgmq.read("my_queue")
.as(TestMessage.class)
.visibilityTime(30)
.polling()
.values(10)
.forEach(m ->
LOG.info("Message: {}, enqueuedAt: {}, readCount: {}, vt: {}",
m.getMessage(),
m.getEnqueuedAt(),
m.getReadCount(),
m.getVisibilityTime())
);
Project is still on development stage, and not ready for production use. Still requires more tests, improvements and adaptations for the Java world.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
Feel free to open issues if you find any, I appreciate any help in making the project better.
This project is licensed under the terms of the MIT license. See the LICENSE file for details.