Content-Length: 334135 | pFad | https://github.com/tmountain/deno-pgmq

79 GitHub - tmountain/deno-pgmq: Postgres Message Queue (PGMQ) Deno Client Library
Skip to content

tmountain/deno-pgmq

Repository files navigation

deno-pgmq

Postgres Message Queue (PGMQ) Deno Client Library

https://deno.land/x/pgmq@v0.2.1

Installation

To use deno-pgmq in your Deno project, simply import it directly from the module URL.

For example:

import { Pgmq } from "https://deno.land/x/pgmq@v0.2.1/mod.ts";

Runtime Environment

Due to a Deno bug, please make sure that you are using Deno 1.44.1 or later. If you are using this library with Supabase edge functions, make sure that the reported runtime compatibility matches this (example below):

Using supabase-edge-runtime-1.58.3 (compatible with Deno v1.45.2)

Environment Variables (Examples)

DATABASE_URL=postgres://postgres:password@localhost:5432/postgres
MAX_POOL_SIZE=20
LAZY=true

Usage

First, Start a Postgres instance with the PGMQ extension installed:

docker run -d --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432 quay.io/tembo/pgmq-pg:latest

Then:

import { Pgmq } from "https://deno.land/x/pgmq@v0.2.1/mod.ts";

console.log("Connecting to Postgres...");
// Specify the connection parameters manually
let pgmq: Pgmq;
try {
  pgmq = await Pgmq.new({
    dsn:
      "postgresql://postgres:postgres@127.0.0.1:54322/postgres?sslmode=require",
    // Optional parameters
    caFilePaths: ["./certs/prod-ca-2021.crt"],
  });
} catch (err) {
  console.error("Failed to connect to Postgres", err);
  Deno.exit(1);
}

// You can also use environment variables to set the connection parameters
// $ export DATABASE_URL='postgresql://postgres:postgres@localhost:54322/postgres'
// $ export LAZY=true
// $ export MAX_POOL_SIZE=20
// const pgmq = await Pgmq.new()

const qName = "my_queue";
console.log(`Creating queue ${qName}...`);

await pgmq.queue.create(qName).catch((err) => {
  console.error("Failed to create queue", err);
  Deno.exit(1);
});

interface Msg {
  id: number;
  name: string;
}

const msg: Msg = { id: 1, name: "testMsg" };
console.log("Sending message...");
const msgId = await pgmq.msg.send(qName, msg).catch((err) => {
  console.error("Failed to send message", err);
  Deno.exit(1);
});

const vt = 30;
const receivedMsg = await pgmq.msg.read<Msg>(qName, vt).catch((err) => {
  console.error("No messages in the queue", err);
  Deno.exit(1);
});

console.log("Received message...");
if (receivedMsg) {
  console.dir(receivedMsg.message, { depth: null });
} else {
  console.log("No message received.");
}

console.log("Archiving message...");
await pgmq.msg.archive(qName, msgId).catch((err) => {
  console.error("Failed to archive message", err);
  Deno.exit(1);
});

API

Supported Functionalities

Tasks

The following tasks are available:

$ deno task test
$ deno task lint
$ deno task fmt
$ deno task coverage

About

Postgres Message Queue (PGMQ) Deno Client Library

Resources

License

Stars

Watchers

Forks

Packages

No packages published








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/tmountain/deno-pgmq

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy