The JVM SDK currently only supports legacy versions of Nitric prior to v1. This version is maintained for compatibility with existing projects and not recommended for new projects. New projects should be started using a supported SDK (presented automatically using the `nitric new` command) orget in touch to request an update to the latest version.
JVM - queue()
Creates a new Queue to send and receive asynchronous tasks.
import io.nitric.Nitric;
import io.nitric.resources.QueuePermission;
public class Application {
public static void main(String[] args) {
var queue = Nitric.INSTANCE.queue("batch").with(QueuePermission.Send);
Nitric.INSTANCE.run();
}
}
Parameters
- Name
name
- Required
- Required
- Type
- String
- Description
The unique name of this Queue within the app. Subsequent calls to
queue
with the same name will return the same object.
Access
All Nitric resources provide access permissions you can use to specify the level of access your code needs to the resource. See here for details Access Control documentation.
Available permissions:
QueuePermission.Send
This permission allows your code to send new tasks to the queue.
QueuePermission.Receive
This permission allows your code to receive tasks from the queue.
In most instances, code should either send to or receive from a queue, usually not both.
Examples
Create a Queue
import io.nitric.Nitric;
import io.nitric.resources.QueuePermission;
public class Application {
public static void main(String[] args) {
var queue = Nitric.INSTANCE.queue("batch").with(QueuePermission.Send);
Nitric.INSTANCE.run();
}
}
Receive tasks from a queue
import io.nitric.Nitric;
import io.nitric.resources.QueuePermission;
public class Application {
public static void main(String[] args) {
var queue = Nitric.INSTANCE.queue("batch").with(QueuePermission.Receive);
var tasks = queue.receive(10);
Nitric.INSTANCE.run();
}
}