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.
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.
- Open the navigation menu and click Developer Services. Under Application Integration, click Queues.
- On the left side of the screen, click Queues.
- In the list of existing queues, click the name of a queue to display its details page.
- Under Resources, click Message.
- Click Actions, then click Send message.
- If needed, enter a value for Channel ID. If you don't provide a Channel ID, the message is published at the queue level.
- Enter a message, and then click Send message.
Details about the sent message are displayed.
- Click Send another message to send another message. To close the panel and return to the Queue details page, click 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 optionalretentionInSeconds
andvisibilityInSeconds
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.