Interface IPubSubApi
Allows you to publish messages to a given topic, and also to subscribe to new messages on a given topic.
Namespace: Ipfs.CoreApi
Assembly: Ipfs.Core.dll
Syntax
public interface IPubSubApi
Remarks
This is an experimental feature. It is not intended in its current state to be used in a production environment.
To use, the daemon must be run with '--enable-pubsub-experiment'.
Methods
| Improve this Doc View SourcePeersAsync(String, CancellationToken)
Get the peers that are pubsubing with us.
Declaration
Task<IEnumerable<Peer>> PeersAsync(string topic = null, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | topic | When specified, only peers subscribing on the topic are returned. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<IEnumerable<Peer>> | A task that represents the asynchronous operation. The task's value is a sequence of Peer. |
PublishAsync(String, Byte[], CancellationToken)
Publish a binary message to a given topic.
Declaration
Task PublishAsync(string topic, byte[] message, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | topic | The topic name. |
Byte[] | message | The message to publish. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous operation. |
PublishAsync(String, Stream, CancellationToken)
Publish a binary message to a given topic.
Declaration
Task PublishAsync(string topic, Stream message, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | topic | The topic name. |
Stream | message | The message to publish. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous operation. |
PublishAsync(String, String, CancellationToken)
Publish a string message to a given topic.
Declaration
Task PublishAsync(string topic, string message, CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
String | topic | The topic name. |
String | message | The message to publish. |
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous operation. |
SubscribeAsync(String, Action<IPublishedMessage>, CancellationToken)
Subscribe to messages on a given topic.
Declaration
Task SubscribeAsync(string topic, Action<IPublishedMessage> handler, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
String | topic | The topic name. |
Action<IPublishedMessage> | handler | The action to perform when a IPublishedMessage is received. |
CancellationToken | cancellationToken | Is used to stop the topic listener. When cancelled, the OperationCanceledException is NOT raised. |
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous operation. |
Remarks
The handler
is invoked on the topic listener thread.
SubscribedTopicsAsync(CancellationToken)
Get the subscribed topics.
Declaration
Task<IEnumerable<string>> SubscribedTopicsAsync(CancellationToken cancel = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
Type | Description |
---|---|
Task<IEnumerable<String>> | A task that represents the asynchronous operation. The task's value is a sequence of String for each topic. |