Class Queue


  • public class Queue
    extends Object
    Provides a Queue API queue class.

    The example below illustrates the Queue API.

    
     import io.nitric.api.queue.Queues;
     import io.nitric.api.queue.Task;
     import io.nitric.api.queue.ReceivedTask;
     ...
    
     String orderId = ...
     String serialNumber = ...
    
     var payload = Map.of("orderId", orderId, "serialNumber", serialNumber);
     var task = Task.build(payload);
    
     // Send a task to the 'shipping' queue
     var queue = Queues.queue("shipping");
     queue.send(task);
    
     // Receive a list of tasks from the 'shipping' queue
     List<ReceivedTask> tasks = queue.receive(100);
    
     // Complete the first shipping task
     var shippingTask = tasks.get(0);
     shippingTask.complete();
     
    See Also:
    Queues
    • Method Detail

      • getName

        public String getName()
        Return the queue name.
        Returns:
        the queue name
      • send

        public FailedTask send​(Task task)
        Send the given task to the client queue.
        Parameters:
        task - the task to send to the queue (required)
        Returns:
        null if task successfully sent, or a failed task otherwise
      • sendBatch

        public List<FailedTask> sendBatch​(List<Task> tasks)
        Send the given tasks to the client queue in a batch, and return any tasks which failed to send.
        Parameters:
        tasks - the list of task to send as a batch (required)
        Returns:
        the list of tasks which failed to send, or an empty list if all were successfully sent
      • receive

        public List<ReceivedTask> receive​(int limit)
        Return receive a maximum specified number of tasks from the queue.
        Parameters:
        limit - the maximum number of tasks to receive from the queue
        Returns:
        the tasks from the client queue
      • toString

        public String toString()
        Return the string representation of this object.
        Overrides:
        toString in class Object
        Returns:
        the string representation of this object