Python - topic.publish()
Publishes a topic.
from nitric.resources import topic
from nitric.api import Event
updates = topic('updates').allow('publishing')
await updates.publish(Event(
payload={'something': 'amazing happened'}
))
Parameters
- Name
event
- Required
- Required
- Type
- Event
- Description
The event to publish to the topic.
- Name
id
- Optional
- Optional
- Type
- string
- Description
Unique ID to apply to the event.
- Name
payload
- Required
- Required
- Type
- dict
- Description
Payload to send with the event.
- Name
payloadType
- Optional
- Optional
- Type
- string
- Description
A hint to the type of payload supplied.
Examples
Publish a topic
from nitric.resources import topic
from nitric.api import Event
updates = topic('updates').allow('publishing')
await updates.publish(Event(
payload={'something': 'amazing happened'}
))
Notes
- If an id is not supplied with an event, a UUID(v4) will be generated for you.
- A function may subscribe to OR publish to a topic but not both. This is in place to stop functions calling themselves infinitely.