@cloudamqp/amqp-client
Version:
AMQP 0-9-1 client, both for browsers (WebSocket) and node (TCP Socket)
59 lines • 1.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AMQPMessage = void 0;
class AMQPMessage {
get isAcked() {
return this.acked;
}
constructor(channel) {
this.exchange = "";
this.routingKey = "";
this.properties = {};
this.bodySize = 0;
this._rawBytes = null;
this.bodyPos = 0;
this.body = null;
this.deliveryTag = 0;
this.consumerTag = "";
this.redelivered = false;
this.acked = false;
this.channel = channel;
}
bodyToString() {
if (this._rawBytes) {
if (typeof Buffer !== "undefined")
return Buffer.from(this._rawBytes).toString();
else
return new TextDecoder().decode(this._rawBytes);
}
else {
return null;
}
}
bodyString() {
return this.bodyToString();
}
ack(multiple = false) {
if (this.acked)
return Promise.resolve();
this.acked = true;
return this.channel.basicAck(this.deliveryTag, multiple);
}
nack(requeue = false, multiple = false) {
if (this.acked)
return Promise.resolve();
this.acked = true;
return this.channel.basicNack(this.deliveryTag, requeue, multiple);
}
reject(requeue = false) {
if (this.acked)
return Promise.resolve();
this.acked = true;
return this.channel.basicReject(this.deliveryTag, requeue);
}
cancelConsumer() {
return this.channel.basicCancel(this.consumerTag);
}
}
exports.AMQPMessage = AMQPMessage;
//# sourceMappingURL=amqp-message.js.map