Skip to main content

Message Queues

The queue manager allows you to communicate different parts of your application and execute cloud functions asynchronously. A message queue provides a buffer that temporarily stores messages and dispatches them to their consuming service.

Typically, in Altogic, you submit messages to a queue in your backend app services using the Submit Message to Queue node. However, with Altogic's client library by calling the submitMessage method, you can manually send messages to your selected queue for processing. Additionally, you can also add delay between message submission to the queue and the actual processing of the submitted message.

Submit message to queue

You can submit messages to the queue using the submitMessage method.

info

It submits a message to the specified message queue to execute your cloud function asynchronously.

  • After the message is submitted, the service defined in your message queue configuration is invoked if there is no delay. If there is delay, then the message waits for the specified delay duration and then sent to the service for processing.
  • This cloud function processes the input message and performs necessary tasks defined in its service flow.
  • The structure of the message (e.g., key-value pairs) is defined by the Start Node of your queue service.
let queueName = "sendWelcomeEmail";
let messageBody = {
name: "Rooby",
email: "[email protected]",
};

// Submit a message to a `sendWelcomeEmail` queue for asychronous processing, no delay, process the message immediately
const { info, errors } = await altogic.queue.submitMessage(queueName, messageBody);

// Process the message after 24 hours (e.g., 60 x 60 x 24 = 86400 seconds)
const { info, errors } = await altogic.queue.submitMessage(queueName, messageBody, 86400);
Example response
{
"info": {
"messageId": "6237ae0f45aba7a695579b8f",
"queueId": "6237ad734625ff4ccdbe6be3",
"queueName": "sendWelcomeEmail",
"submittedAt": "2022-03-20T22:43:27.485Z",
"status": "pending"
},
"errors": null
}

Parameters

Here you can find parameters for the submitMessage method.

#

Name

Data type

Required

Description

1queueNameOrIdStringYesThe name or id of the message queue.
2messageObjectYesThe message payload (JSON object) that will be submitted to the message queue.
3delayNumberNoThe number of seconds to delay the messages in queue before dispacthing them to their consuming service.
info
  • If successful, it returns information about the submitted message, including the messageId of the submitted message.

  • You can use messageId to check the processing status of your message by calling getMessageStatus method. In case of any errors, returns the errors that occurred.

note

If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.

Get message status

You can retrieve the status of a message using the getMessageStatus method.

let messageId = "6237ae0f45aba7a695579b8f";

// Get the status of submitted message whether it has been completed processing or not
const { info, errors } = await altogic.queue.getMessageStatus(messageId);
Example response
{
"info": {
"messageId": "6237ae0f45aba7a695579b8f",
"queueId": "6237ad734625ff4ccdbe6be3",
"queueName": "sendWelcomeEmail",
"submittedAt": "2022-03-20T22:54:31.676Z",
"status": "completed",
"startedAt": "2022-03-20T22:54:31.697Z",
"completedAt": "2022-03-20T22:54:31.723Z",
"delay": 86400
},
"errors": null
}

Parameters

Here you can find parameters for the getMessageStatus method.

#

Name

Data type

Required

Description

1messageIdStringYesThe id of the submitted message.
caution

The last seven days of the message logs are kept. If you try to get the status of a message that has been submitted earlier, this method returns null.

note

If the client library key is set to enforce session, an active user session is required (e.g., user needs to be logged in) to call this method.