Skip to content
/ pgmq4j Public

Java library for pgmq, lightweight message queue built on top of PostgreSQL by @tembo-io

License

Notifications You must be signed in to change notification settings

emrygun/pgmq4j

Repository files navigation

pgmq4j the "pgmq Java Client Library"

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

Example Usages

Here are some examples of how to use the library.

Create a queue:

PGMQueueFactory pgmqFactory = new PGMQueueFactory(jsonSerializer, connectionProvider);
PGMQueue pgmq = pgmqFactory.create();
pgmq.create("my_queue");

Send and read a message:

// 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 and read multiple messages:

// 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 Stage

Project is still on development stage, and not ready for production use. Still requires more tests, improvements and adaptations for the Java world.

Contributing

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.

License

This project is licensed under the terms of the MIT license. See the LICENSE file for details.

About

Java library for pgmq, lightweight message queue built on top of PostgreSQL by @tembo-io

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages