This server-side API class provides methods to generate and send messages to an external queue based on RabbitMQ.
Use this method to return error messages if an error occurred while sending the messages.
Return:
Type | Description |
---|---|
Array of Strings | Error values. |
Example:
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()); |
Use this method to send a message to a selected queue.
Maximum message length – 26000 characters. |
Parameter(s):
Name | Type | Mandatory | Default value | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
routingKey | String | Y | N | ||||||||||||||||||||||||||||||||||||||||||||||||||||
payload | String | Y | N | ||||||||||||||||||||||||||||||||||||||||||||||||||||
options | Object | N | N
|
Return:
Type | Description |
---|---|
SimpleExternalRabbitMQ | This method returns an instance on which it was called. |
Example:
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()); |
Use this method to send an array of messages to a selected queue.
Maximum message length – 26000 characters. |
Parameter(s):
Name | Type | Mandatory | Default value | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
routingKey | String | Y | N | ||||||||||||||||||||||||||||||||||||||||||||||||||||
payloads | Array of Strings | Y | N | ||||||||||||||||||||||||||||||||||||||||||||||||||||
options | Object | N | N
|
Return:
Type | Description |
---|---|
SimpleExternalRabbitMQ | This method returns an instance on which it was called. |
Example:
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()); |