Publishing Messages to a Channel

Publish messages to a specific channel within a queue.

Channels are ephemeral destinations within a queue. Publishing messages to a channel within a queue requires only an extra parameter. Channels don't require explicit creation or deletion. Messages published to a channel are available for consumption from both the queue or the channel level. For more information, see Channels.

Publishing messages requires permissions to the queue and access to its Messages endpoint.

A message contains a payload in the form of a string. When you publish messages using a PutMessages request, you can include a channel ID and specify its visibility timeout and retention.

Note

You can specify different channel IDs for different messages in the same request. However, publishing messages to multiple channels in one request can result in partial failures. Some messages might be published successfully and other messages in the same request might fail. Responses to a PutMessages request that specifies channels include failure information.
  • While you can use the Console to publish test messages to a channel, you use the CLI, API, or an SDK to populate a queue and its channels. See Ways to Access Queue for more information.

    1. On the Queues list page, select the queue that you want to work with. If you need help finding the list page or the queue, see Listing Queues.
    2. On the details page for the queue, select Send message.
    3. If needed, enter a value for Channel ID. If you don't provide a Channel ID, the message is published at the queue level.
    4. Enter a message, and then select Send message.

      Details about the sent message are displayed.

    5. Select Send another message to send another message. To close the panel and return to the Queue details page, select Cancel.
  • Use the oci queue messages put-messages command and required parameters to publish messages to a queue:

    oci queue messages put-messages --messages file://messages.json --queue-id <queue_OCID>

    The channel is specified as metadata associated with the message. For example:

    {
      "messages": [
        {
          "content": "1",
          "metadata" : {"channelId" : "ch1"}
        },
        {
          "content": "2",
          "metadata" : {"channelId" : "ch2"}
        },
      ],
      "retentionInSeconds": 600
    }

    For a complete list of parameters and values for CLI commands, see the CLI Command Reference.

  • Use the PutMessages operation to publish messages to a channel. A PutMessages request contains a list of messages with a channelId specified as metadata, and optional retentionInSeconds and visibilityInSeconds parameters. For example:

    {
      "messages": [
        {
          "content": "1",
          "metadata" : {"channelId" : "ch1"}
        },
        {
          "content": "2",
          "metadata" : {"channelId" : "ch2"}
        },
      ],
      "retentionInSeconds": 600
    }

    The API returns the id for each message.

    For information about using the API and signing requests, see REST API documentation and Security Credentials. For information about SDKs, see SDKs and the CLI.