You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:v1.2.1
Then:
import{Pgmq}from'pgmq-js';console.log('Connecting to Postgres...');constpgmq=awaitPgmq.new({host: 'localhost',database: 'postgres',password: 'password',port: 5432,user: 'postgres',ssl: false,},// { skipExtensionCreation: true }, Set this if you want to bypass extension creation (e.g. dbdev users).).catch((err)=>{console.error('Failed to connect to Postgres',err);});constqName='my_queue';console.log(`Creating queue ${qName}...`);awaitpgmq.queue.create(qName).catch((err)=>{console.error('Failed to create queue',err);});interfaceMsg{id: number;name: string;}constmsg: Msg={id: 1,name: 'testMsg'};console.log('Sending message...');constmsgId=awaitpgmq.msg.send(qName,msg).catch((err)=>{console.error('Failed to send message',err);});constvt=30;constreceivedMsg=awaitpgmq.msg.read<Msg>(qName,vt).catch((err)=>{console.error('No messages in the queue',err);});console.log('Received message...');console.dir(receivedMsg.message,{depth: null});console.log('Archiving message...');awaitpgmq.msg.archive(qName,msgId).catch((err)=>{console.error('Failed to archive message',err);});