Package io.nitric.api.queue
Class QueueClient
- java.lang.Object
-
- io.nitric.api.queue.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QueueClient.Builder
Provides a QueueClient Builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static QueueClient
build(String queue)
Return a new QueueClient with the specified queue name.void
complete(String leaseId)
Complete the task specified by the given lease id.static QueueClient.Builder
newBuilder()
Create an new QueueClient builder.List<Task>
receive(int limit)
Return receive a maximum specified number of tasks from the queue.void
send(Task task)
Send the given task to the client queue.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.String
toString()
-
-
-
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
-
-