Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/craigpastro/pgmq-go
A Go (Golang) client for Postgres Message Queue (PGMQ)
https://github.com/craigpastro/pgmq-go
go golang postgres postgres-extension postgresql queue
Last synced: about 1 month ago
JSON representation
A Go (Golang) client for Postgres Message Queue (PGMQ)
- Host: GitHub
- URL: https://github.com/craigpastro/pgmq-go
- Owner: craigpastro
- License: mit
- Created: 2023-08-08T17:31:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-07T19:05:55.000Z (about 2 months ago)
- Last Synced: 2024-11-07T20:18:33.797Z (about 2 months ago)
- Topics: go, golang, postgres, postgres-extension, postgresql, queue
- Language: Go
- Homepage:
- Size: 125 KB
- Stars: 42
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pgmq-go
[![Go Reference](https://pkg.go.dev/badge/github.com/craigpastro/pgmq-go.svg)](https://pkg.go.dev/github.com/craigpastro/pgmq-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/craigpastro/pgmq-go)](https://goreportcard.com/report/github.com/craigpastro/pgmq-go)
[![CI](https://github.com/craigpastro/pgmq-go/actions/workflows/push_to_main.yaml/badge.svg)](https://github.com/craigpastro/pgmq-go/actions/workflows/push_to_main.yaml)
[![codecov](https://codecov.io/github/craigpastro/pgmq-go/branch/main/graph/badge.svg?token=00AJODX77Z)](https://codecov.io/github/craigpastro/pgmq-go)A Go (Golang) client for
[Postgres Message Queue](https://github.com/tembo-io/pgmq) (PGMQ). Based loosely
on the [Rust client](https://github.com/tembo-io/pgmq/tree/main/pgmq-rs).## Usage
Start a Postgres instance with the PGMQ extension installed:
```shell
docker run -d --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432 quay.io/tembo/pgmq-pg:latest
```Then
```go
package mainimport (
"context"
"fmt""github.com/craigpastro/pgmq-go"
)func main() {
ctx := context.Background()q, err := pgmq.New(ctx, "postgres://postgres:password@localhost:5432/postgres")
if err != nil {
panic(err)
}err = q.CreateQueue(ctx, "my_queue")
if err != nil {
panic(err)
}id, err := q.Send(ctx, "my_queue", json.RawMessage(`{"foo": "bar"}`))
if err != nil {
panic(err)
}msg, err := q.Read(ctx, "my_queue", 30)
if err != nil {
panic(err)
}// Archive the message by moving it to the "pgmq.a_" table.
// Alternatively, you can `Delete` the message, or read and delete in one
// call by using `Pop`.
_, err = q.Archive(ctx, "my_queue", id)
if err != nil {
panic(err)
}
}
```## Contributions
We :heart: contributions.