https://github.com/datenhahn/simple-postgres-queue
This is a simple message queue implementation based on the postgresql database and the `SELECT FOR UPDATE` table locking.
https://github.com/datenhahn/simple-postgres-queue
Last synced: about 1 month ago
JSON representation
This is a simple message queue implementation based on the postgresql database and the `SELECT FOR UPDATE` table locking.
- Host: GitHub
- URL: https://github.com/datenhahn/simple-postgres-queue
- Owner: datenhahn
- License: apache-2.0
- Created: 2020-03-17T21:40:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-09-08T01:10:05.000Z (almost 4 years ago)
- Last Synced: 2025-02-23T22:28:14.673Z (over 1 year ago)
- Language: Java
- Size: 22.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple Postgres Queue
This is a simple message queue implementation based on the postgresql database and the `SELECT FOR UPDATE`
table locking.
Why another message queue implementation?
* You have a postgresql database and want to make use of the existing scaling and backup features
* The application has only moderate performance requirements, but high requirements regarding data consistency
* Debugging and admin friendlyness are keyfeatures
* Simple code which you can understand (both the queue implemenation, as well as client code)
## Usage
see `src/main/java/de/ecodia/simplequeue/examples/ExampleApp.java` for the full example.
```java
// dataSource is some standard jdbc datasource
var queue = new SimpleQueue(dataSource);
queue.publish("myqueue", "well that was easy");
queue.subscribe("myqueue", x -> {
System.out.println(x.getMessage());
});
```
## Subscriber Callback
The subscriber callback has access to the message properties:
id
queue
traceId
created
updated
publisherId
subscriberId
status
statusText
message
The subscriber and publisher ID can be set as `hostId`in the constructor.
public SimpleQueue(DataSource ds, String hostId, boolean notifyProcessing, String tableName)
If parameter `notifyProcessing` is set to true it will update the table to state "PROCESSING" when starting
to process the callback. If set to false it will only update after finishing the callback.