Using the Momento Topics (pub/sub) API with Momento Cache
Momento Topics is a messaging pattern that allows for real-time communication between parts of a distributed application. It enables you to publish (produce) values to a topic, as well as subscribe (consume) from a topic. This page details the Momento API methods for interacting with Momento Topics.
For in-depth information, see Momento Topics.
Topics methods
Subscribe
This method subscribes to a topic to receive new values with a stateful connection.
Name | Type | Description |
---|---|---|
cacheName | String | Name of the cache where the topic exists. |
topicName | String | Name of the topic to subscribe to. |
- Go
- Node.js
Method response object
- Success - Returns a subscription object.
- Error
See response objects for specific information.
With the returned subscription object, once put in a for loop, your code will receive an event when a new value is published to the Topic.
Publish
Publishes a message to a topic.
Name | Type | Description |
---|---|---|
cacheName | String | Name of the cache where the topic exists. |
topicName | String | Name of the topic to publish the value to. |
value | String / bytes | Value to publish to the topic. |
- Go
- Node.js
Method response object
- Success
- Error
See response objects for specific information.
TopicClient
Instead of the CacheClient, as used in most Momento Cache API calls, for Topics you use a TopicClient object.