UNPKG

@mqueue/amqplib

Version:

MQueue adapter for amqplib AMQP v0.9.1

2 lines 1.46 kB
import {connect}from'amqplib';var n=class{constructor(t,e){this.channel=t;this.queueName=e;}type="amqplib";static async connect(t,e,{socketOptions:o}={}){let c=await(await connect(t,o)).createChannel();return await c.prefetch(1),new this(c,e)}async healthcheck(){await this.channel.assertQueue(this.queueName,{durable:true});}async close(){await this.channel.close();}async consume(t){await this.channel.consume(this.queueName,async e=>{e!==null&&await t({raw:e,accept:async()=>{this.channel.ack(e);},reject:async()=>{this.channel.nack(e,false,false);},transport:{name:this.queueName},message:{isRedelivered:e.fields.redelivered,headers:e.properties.headers??{},body:e.content}});},{noAck:false});}};var i=class{constructor(t,e){this.client=t;this.queueName=e;}type="amqplib";static async connect(t,e,{socketOptions:o}={}){let c=await(await connect(t,o)).createChannel();return new this(c,e)}async sendMessage(t){if(!this.client.sendToQueue(this.queueName,t.body,{contentType:"application/json",contentEncoding:"binary",headers:t.headers}))throw new Error(`Message failed to send to ${this.type} queue`)}async healthcheck(){await this.client.assertQueue(this.queueName,{durable:true}).catch(t=>{throw t});}async close(){await this.client.close();}};var a=class{constructor(){}static Outgoing=i;static Incoming=n};export{n as AmqplibIncomingQueue,i as AmqplibOutgoingQueue,a as AmqplibQueue};//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map