https://github.com/emrygun/pgmq4j
Java library for pgmq, lightweight message queue built on top of PostgreSQL by @tembo-io
https://github.com/emrygun/pgmq4j
java postgresql tembo
Last synced: 2 months ago
JSON representation
Java library for pgmq, lightweight message queue built on top of PostgreSQL by @tembo-io
- Host: GitHub
- URL: https://github.com/emrygun/pgmq4j
- Owner: emrygun
- License: mit
- Created: 2024-06-11T20:46:05.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-30T15:37:21.000Z (about 2 years ago)
- Last Synced: 2025-07-01T19:08:21.285Z (about 1 year ago)
- Topics: java, postgresql, tembo
- Language: Java
- Homepage:
- Size: 103 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pgmq4j the "pgmq Java Client Library"
This library provides a Java interface for interacting with [PGMQ](https://github.com/tembo-io/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:
```java
PGMQueueFactory pgmqFactory = new PGMQueueFactory(jsonSerializer, connectionProvider);
PGMQueue pgmq = pgmqFactory.create();
pgmq.create("my_queue");
```
### Send and read a message:
```java
// Send and read a message test
TestMessage testMessage = new TestMessage("test", Instant.now().getEpochSecond());
pgmq.send("my_queue", testMessage);
Optional message = pgmq.read("my_queue")
.as(TestMessage.class)
.visibilityTime(30)
.oneValue();
```
### Send and read multiple messages:
```java
// Send multiple messages and read values
List 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](LICENSE) file for details.