Python - queue()
Creates a new Queue to process asynchronous messages.
from nitric.resources import queue
from nitric.application import Nitric
batch_queue = queue('batch').allow('enqueue')
Nitric.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 service needs to the resource. See here for details Access Control documentation.
Available permissions:
enqueue
This permission allows your code to enqueue messages.
dequeue
This permission allows your code to dequeue messages.
Notes
In most instances code should either enqueue or dequeue, usually not both.
Examples
Create a Queue
from nitric.resources import queue
from nitric.application import Nitric
batch_queue = queue('batch').allow('enqueue')
Nitric.run()
Enqueue messages
from nitric.resources import queue
from nitric.application import Nitric
batch_queue = queue('batch').allow('enqueue')
payload = {}
await batch_queue.send(payload)
Nitric.run()
Dequeue messages
from nitric.resources import queue
from nitric.application import Nitric
payload = {}
batch_queue = queue('batch').for('dequeue')
messages = await batch_queue.dequeue(10)
Nitric.run()