Python - topic.publish()

Publishes a topic.

from nitric.resources import topic
from nitric.application import Nitric
from nitric.api import Event

updates = topic('updates').allow('publishing')

await updates.publish({
  'something': 'amazing happened'
})

Nitric.run()

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.application import Nitric
from nitric.api import Event

updates = topic('updates').allow('publishing')

await updates.publish({
  'something': 'amazing happened'
})

Nitric.run()

Notes

  • A service may subscribe to OR publish to a topic but not both. This is in place to stop services calling themselves infinitely.