-
Notifications
You must be signed in to change notification settings - Fork 37
Message class
The Message class defines an AMQP message.
A detailed reference explaining the meaning and use of each method and property.
constructor ( content?: any,
options?: any)
Creates a new message.
content?: any
: message content.options?: any
: message options, as defined in amqplib, defaults to{}
.import * as Ampq from "amqp-ts"; msg1 = new Amqp.Message("TestMessage"); msg2 = new Amqp.Message({name: "TemporaryTest", value: 12345}, {expiration: 100000});
setContent ( content: any );
Replaces the message content with the given content. It transforms the given content to a
Buffer
:
- Buffer : send the content as is (no preprocessing).
- string : create a Buffer from the string and send that buffer.
- everything else : create a Buffer from the to JSON converted object and, if not defined, set the contentType option to
"application/json"
.
content?: any
: new message content.message.setContent("TestMessage");
message.getContent (): any
Returns the content from the content property and converts it to a javascript structure if the contentType property is set to
application/json
, otherwise it converts the content to a string.
any
: converted content buffer.var msgContent = message.getContent();
message.sendTo ( destination: Exchange | Queue,
routingKey?: string)
Send the message to an exchange or queue.
message.sendTo(exchange);
message.ack (allUpTo?: boolean)
Acknowledges a message. Only works inside consumer function of [queue.activateConsumer](Queue class#activateConsumer) or [exchange.ActivateConsumer](Exchange class#activateConsumer).
allUpTo?: boolean
: acknowledge all messages upto this one, defaults tofalse
.queue.activateConsumer((msg) => { //process the msg msg.ack(); });
message.nack (allUpTo?: boolean, requeue?: boolean)
Does explicitly not acknowledge the message. Only works inside consumer function of [queue.activateConsumer](Queue class#activateConsumer) or [exchange.ActivateConsumer](Exchange class#activateConsumer).
allUpTo?: boolean
: nacks all messages upto this one, defaults tofalse
.requeue?: boolean
: requeue the nacked message, defaults totrue
.queue.activateConsumer((msg) => { //process the msg if(we_cannot_process_this_message) { msg.nack(); } else { msg.ack(); } });
message.reject (requeue?: boolean)
Does reject the message. Only works inside consumer function of [queue.activateConsumer](Queue class#activateConsumer) or [exchange.ActivateConsumer](Exchange class#activateConsumer).
requeue?: boolean
: requeue the rejected message, defaults totrue
.queue.activateConsumer((msg) => { //process the msg if(we_cannot_process_this_message) { msg.reject(); } else { msg.ack(); } });
message.content: Buffer
Buffer that contains the content of the message that is sent or received.
message.fields: any
Structure that contains the fields of the message that is received.
message.properties: any
Structure that contains the properties of the message that is received or the options of the message that will be sent.