UNPKG

@mqueue/azure-service-bus

Version:

MQueue adapter for Azure Service Bus

2 lines 1.98 kB
import {ServiceBusClient}from'@azure/service-bus';var s=class{constructor(i,e,t){this.connection=i;this.channel=e;this.queueName=t;}type="azure-service-bus";static async connect(i,e,t){let n=new ServiceBusClient(i,t),r=await n.createReceiver(e,{skipParsingBodyAsJson:true});return new this(n,r,e)}async healthcheck(){if(this.channel.isClosed)throw new Error("Azure Service Bus Sender unexpectedly closed connection")}async close(){return await this.connection.close()}async consume(i){this.channel.subscribe({processMessage:async e=>{if(!e.body)throw new Error("Received message with no body");if(!e.messageId)throw new Error("Received message with no message ID");if(!e.applicationProperties)throw new Error("Received message with no headers");let t={};for(let[n,r]of Object.entries(e.applicationProperties))r!==null&&(t[n]=r.toString());await i({raw:e,accept:async()=>{await this.channel.completeMessage(e);},reject:async n=>{await this.channel.deadLetterMessage(e,n?{deadLetterReason:n.name,deadLetterErrorDescription:n.message}:void 0);},transport:{name:this.queueName},message:{isRedelivered:(e.deliveryCount??0)>0,headers:t,body:Buffer.from(e.body,"binary")}});},processError:async e=>{console.error(e);}},{autoCompleteMessages:false});}};var c=class{constructor(i,e,t){this.connection=i;this.channel=e;this.queueName=t;}type="azure-service-bus";static async connect(i,e,{clientOptions:t}={}){let n=new ServiceBusClient(i,t),r=n.createSender(e);return new this(n,r,e)}async healthcheck(){if(this.channel.isClosed)throw new Error("Azure Service Bus Sender unexpectedly closed connection")}async close(){return await this.connection.close()}async sendMessage(i){await this.channel.sendMessages({applicationProperties:i.headers,body:i.body});}};var o=class{constructor(){}static Outgoing=c;static Incoming=s};export{s as AzureServiceBusIncomingQueue,c as AzureServiceBusOutgoingQueue,o as AzureServiceBusQueue};//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map