Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This server-side API class is intended provides methods to generate and send messages to an external queue based on RabbitMQ.

getErrors()


If a message cannot be sent, Use this method displays an error message.Use it to check your script for errorsto return error messages if an error occurred while sending the messages.

Return:

TypeDescription
Array of StringsError values.

Example:

Code Block
languagejs
themeConfluence
titlegetErrors()
linenumberstrue
const rabbitMq = new SimpleExternalRabbitMQ('nofication-service');

const payload = {
    userIDs: [2344, 7444],
    message: "Hello!"
}

ss.info(rabbitMq.publishMessage('push-notifications', JSON.stringify(payload), {ContentType: "application/json", Headers: {"X-Source": "simple"}}).getErrors());

publishMessage()


This method sends a message to a selected queue.

Note

Maximum message length – 26000 characters.

Parameter(s):

NameTypeMandatoryDefault value
routingKeyStringYN
payloadStringYN
optionsObjectN

N

Expand
titleSet of fields


FieldTypeValue
Exchangestringnot set
Mandatorybooleanfalse
Immediatebooleanfalse
Headersobject{}
ContentTypestringtext/plain
ContentEncodingstringnot set
DeliveryModeinteger1
Priorityinteger0
CorrelationIdstringnot set
ReplyTostringnot set
Expirationstringnot set
MessageIdstringnot set
Timestampstring0001-01-01 00:00:00
UserIdstringnot set
AppIdstringnot set
Typestringnot set



Return:

TypeDescription
SimpleExternalRabbitMQThis method returns an instance of the same classon which it was called.

Example:

Code Block
languagejs
themeConfluence
titlepublishMessage()
linenumberstrue
const rabbitMq = new SimpleExternalRabbitMQ('nofication-service');

const payload = {
    userIDs: [2344, 7444],
    message: "Hello!"
}

ss.info(rabbitMq.publishMessage('push-notifications', JSON.stringify(payload), {ContentType: "application/json", Headers: {"X-Source": "simple"}}).getErrors());

publishMultipleMessages()


This method sends an array of messages to a selected queue.

Note

Maximum message length – 26000 characters.

Parameter(s):

NameTypeMandatoryDefault value
routingKeyStringYN
payloadsArrayYN
optionsObjectN

N

Expand
titleSet of fields


FieldType
Exchangestringnot set
Mandatorybooleanfalse
Immediatebooleanfalse
Headersobject{}
ContentTypestringtext/plain
ContentEncodingstringnot set
DeliveryModeinteger1
Priorityinteger0
CorrelationIdstringnot set
ReplyTostringnot set
Expirationstringnot set
MessageIdstringnot set
Timestampstring0001-01-01 00:00:00
UserIdstringnot set
AppIdstringnot set
Typestringnot set



Return:

TypeDescription
SimpleExternalRabbitMQThis method returns an instance of the same classon which it was called.

Example:

Code Block
languagejs
themeConfluence
titlepublishMultipleMessages()
linenumberstrue
const rabbitMq = new SimpleExternalRabbitMQ('notification-service');

const messages = [
    {
        userID: 2344,
        message: "Hello, Ivan"
    },
    {
        userID: 7444,
        message: "Hello, Petr"
    }
];

rabbitMq.publishMultipleMessages(
    'push-notifications',
    messages.map(m => JSON.stringify(m)),
    {
        ContentType: "application/json",
        Headers: {
            "X-Source": "simple"
        }
    }
)

ss.info(rabbitMq.getErrors());


Table of Contents
absoluteUrltrue
classfixedPosition
printablefalse