Class QueueClient


  • public class QueueClient
    extends Object

    Provides a Queue API client.

    The example below illustrates the Queue API.

    
      import io.nitric.api.queue.QueueClient;
      import io.nitric.api.queue.Task;
      ...
    
      String orderId = ...
      String serialNumber = ...
    
      var payload = Map.of("orderId", orderId, "serialNumber", serialNumber);
      var task = Task.build(payload);
    
      // Send a task to the 'shipping' queue client
      var client = QueueClient.build("shipping");
      client.send(task);
    
      // Receive a list of tasks from the 'shipping' queue
      List<Task> tasks = client.receive(100);
     
    Since:
    1.0
    See Also:
    Task, FailedTask
    • Method Detail

      • send

        public void send​(Task task)
        Send the given task to the client queue.
        Parameters:
        task - the task to send to the queue (required)
      • 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<Task> 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
      • complete

        public void complete​(String leaseId)
        Complete the task specified by the given lease id.
        Parameters:
        leaseId - the lease id of the task to complete (required)
      • newBuilder

        public static QueueClient.Builder newBuilder()
        Create an new QueueClient builder.
        Returns:
        new QueueClient builder
      • build

        public static QueueClient build​(String queue)
        Return a new QueueClient with the specified queue name.
        Parameters:
        queue - the queue name (required)
        Returns:
        a new QueueClient with the specified queue name
      • toString

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