Dart - queue.enqueue()

Send messages to a queue.

import 'package:nitric_sdk/nitric.dart';
final batchQueue = Nitric.queue("batch").allow([
QueuePermission.enqueue,
]);
final messages = [{ "example": "value" }];
await batchQueue.enqueue(messages);

Parameters

  • Name
    messages
    Required
    Required
    Type
    List<Map<String, dynamic>>
    Description

    A message or an array of messages to send to the queue.

Examples

Send messages to a queue

import 'package:nitric_sdk/nitric.dart';
final batchQueue = Nitric.queue("batch").allow([
QueuePermission.enqueue,
]);
final messages = [
{
"type": "email",
"to": "hello@example.com",
"subject": "Notification",
"message": "A notification from Nitric"
},
{
"type": "SMS",
"to": "+17200000000",
"message": "A text message from Nitric"
},
];
await batchQueue.enqueue(messages);

Dealing with failures

In rare cases when enqueue messages some might fail to be sent. The response from enqueue() will include an array of any messages that failed to send. You can process this array to retry or log the error.

final failed = await batchQueue.enqueue(messages);
messages.forEach((message) {
print(message);
});
Last updated on Nov 4, 2024