Skip to main content
Version: 1.22.3

SimpleExternalRabbitMQ

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

getErrors()


Use this method to return error messages if an error occurred while sending the messages.

Return:

TypeDescription
Array of StringsThis method returns the error values.

Example:

getErrors()
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()


Use this method to send a message to a selected queue.

caution

The maximum message length is 26000 characters.

Parameter(s):

NameTypeMandatoryDefault value
routingKeyStringYN
payloadStringYN
optionsObjectNN
Set of fields for options parameter
FieldTypeValue
UserIdstringnot set
Typestringnot set
Timestampstring0001-01-01 00:00:00
ReplyTostringnot set
Priorityinteger0
MessageIdstringnot set
Mandatorybooleanfalse
Immediatebooleanfalse
Headersobject{}
Expirationstringnot set
Exchangestringnot set
DeliveryModeinteger1
CorrelationIdstringnot set
ContentTypestringtext/plain
ContentEncodingstringnot set
AppIdstringnot set

Return:

TypeDescription
SimpleExternalRabbitMQThis method returns an instance on which it was called.

Example:

publishMessage()
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()


Use this method to send an array of messages to a selected queue.

caution

The maximum message length is 26000 characters.

Parameter(s):

NameTypeMandatoryDefault value
routingKeyStringYN
payloadsArray of StringsYN
optionsObjectNN
Set of fields for options parameter
FieldTypeValue
UserIdstringnot set
Typestringnot set
Timestampstring0001-01-01 00:00:00
ReplyTostringnot set
Priorityinteger0
MessageIdstringnot set
Mandatorybooleanfalse
Immediatebooleanfalse
Headersobject{}
Expirationstringnot set
Exchangestringnot set
DeliveryModeinteger1
CorrelationIdstringnot set
ContentTypestringtext/plain
ContentEncodingstringnot set
AppIdstringnot set

Return:

TypeDescription
SimpleExternalRabbitMQThis method returns an instance on which it was called.

Example:

publishMultipleMessages()
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());