Skip to main content

Cookbook: Publishing

This section presents common recipes for publishing to a topic in AMPS using the Command or Message interfaces. This section provides information on how to configure the request to AMPS. You can adapt this information to your application and the specific interface you are using.

Command: publish

The AMPS server does not return a stream of messages in response to a publish command.

info

AMPS publish commands do not return a stream of messages. A publish command must be used with asynchronous message processing and should typically pass an empty message handler.

Basic Publish

In its simplest form, a publish needs only the topic to publish to and the data to publish. The AMPS client automatically constructs the necessary AMPS headers and formats the full publish command.

In many cases, a publisher only needs to use the basic publish command.

HeaderComment
topic

(required)
Sets the topic to publish to. The topic specified must be a literal topic name. Regular expression characters in the topic name are not interpreted. Some topics in AMPS, such as views and conflated topics, cannot be published to directly. Instead, a publisher must publish to the underlying topics.
dataThe data to publish to the topic. The AMPS client does not interpret, escape, or validate this data: the data is provided to the server verbatim.

Publish with CorrelationId

AMPS provides publishers with a header field that can be used to contain arbitrary data, the correlation_id.

HeaderComment
topic

(required)
Sets the topic to publish to. The topic specified must be a literal topic name. Regular expression characters in the topic name are not interpreted. Some topics in AMPS, such as views and conflated topics, cannot be published to directly. Instead, a publisher must publish to the underlying topics.
dataThe data to publish to the topic. The AMPS client does not interpret, escape, or validate this data: the data is provided to the server verbatim.
correlation_idThe correlation ID to provide on the message. AMPS provides the correlation ID to subscribers. The correlation_id header has no significance for AMPS. The correlation_id may only contain characters that are valid in base-64 encoding.

Publish with Explicit SOW Key

When publishing to a SOW topic that is configured to require an explicit SOW key, the publisher needs to set the sow_key header on the message.

HeaderComment
topic

(required)
Sets the topic to publish to. The topic specified must be a literal topic name. Regular expression characters in the topic name are not interpreted. Some topics in AMPS, such as views and conflated topics, cannot be published to directly. Instead, a publisher must publish to the underlying topics.
dataThe data to publish to the topic. The AMPS client does not interpret, escape, or validate this data: the data is provided to the server verbatim.
sow_keyThe SOW Key to use for this message. This header is only supported for publishes to a topic that requires an explicit SOW Key.