Client: PublisherClient
The HTTP based client for WebSub topic registration and deregistration, and notifying the hub of new updates.
Constructor
Initializes the websub:PublisherClient
.
1websub:PublisherClient publisherClient = check new("https://sample.hub.com");
init (string url, *ClientConfiguration config)
- url string
The URL to publish/notify updates
- config *ClientConfiguration
The
websubhub:ClientConfiguration
for the underlying client or else()
Remote Methods
registerTopic | Registers a topic in a Ballerina WebSub Hub to which the subscribers can subscribe and the publisher will publish updates. |
deregisterTopic | Deregisters a topic in a Ballerina WebSub Hub. |
publishUpdate | Publishes an update to a remote Ballerina WebSub Hub. |
notifyUpdate | Notifies a remote WebSubHub from which an update is available to fetch for hubs that require publishing. |
registerTopic
function registerTopic(string topic) returns TopicRegistrationSuccess | TopicRegistrationError
Registers a topic in a Ballerina WebSub Hub to which the subscribers can subscribe and the publisher will publish updates.
1websubhub:TopicRegistrationSuccess response = check publisherClient->registerTopic("http://websubpubtopic.com");
Parameters
- topic string
The topic to register
Return Type
(TopicRegistrationSuccess | TopicRegistrationError)A websubhub:TopicRegistrationError
if an error occurred registering the topic or else websubhub:TopicRegistrationSuccess
deregisterTopic
function deregisterTopic(string topic) returns TopicDeregistrationSuccess | TopicDeregistrationError
Deregisters a topic in a Ballerina WebSub Hub.
1websubhub:TopicDeregistrationSuccess response = check publisherClient->deregisterTopic("http://websubpubtopic.com");
Parameters
- topic string
The topic to deregister
Return Type
(TopicDeregistrationSuccess | TopicDeregistrationError)A websubhub:TopicDeregistrationError
if an error occurred un registering the topic or else websubhub:TopicDeregistrationSuccess
publishUpdate
function publishUpdate(string topic, map<string> | string | xml | json | byte[ ] payload, string? contentType) returns Acknowledgement | UpdateMessageError
Publishes an update to a remote Ballerina WebSub Hub.
1websubhub:Acknowledgement response = check publisherClient->publishUpdate("http://websubpubtopic.com",{"action": "publish",2"mode": "remote-hub"});
Parameters
- topic string
The topic for which the update occurred
- contentType string? (default ())
The type of the update content to set as the ContentType
header
Return Type
(Acknowledgement | UpdateMessageError)A websubhub:UpdateMessageError
if an error occurred with the update or else websubhub:Acknowledgement
notifyUpdate
function notifyUpdate(string topic) returns Acknowledgement | UpdateMessageError
Notifies a remote WebSubHub from which an update is available to fetch for hubs that require publishing.
1 websubhub:Acknowledgement|websubhub:UpdateMessageError response = check publisherClient->notifyUpdate("http://websubpubtopic.com");
Parameters
- topic string
The topic for which the update occurred
Return Type
(Acknowledgement | UpdateMessageError)A websubhub:UpdateMessageError
if an error occurred with the notification or else websubhub:Acknowledgement