Skip to main content

Processing messages in a queue

Platforms:

Example application that processes messages form a queue and puts information into a bucket

Processing messages in a queue

This pattern creates a bucket and a queue. When messages are pushed the queue an inflight function processes the message and puts the contents of the message into a bucket.

INFO

The inflight function is executed at runtime. During this execution, inflight code can interact with resources through their inflight APIs (e.g. bucket inflight APIS). In this example, information is added to the bucket by using the inflight put API provided by the bucket.

1bring cloud;
2bring util;
3bring expect;
4
5let bucket = new cloud.Bucket();
6let queue = new cloud.Queue();
7
8queue.setConsumer(inflight (message) => {
9  bucket.put("wing.txt", "Hello, {message}");
10}, timeout: 30s);
11
12test "Hello, world!" {
13  queue.push("world!");
14
15  let found = util.waitUntil(() => {
16    log("Checking if wing.txt exists");
17    return bucket.exists("wing.txt");
18  });
19
20  expect.equal(bucket.get("wing.txt"), "Hello, world!");
21}

Resources used in this example

  • Queue - Resource for holding lists of messages.
  • Bucket - Resource for storing data in the cloud.