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 websubHubClientEP = new("http://localhost:9191/websub/publish");
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.
1error? registerTopic = websubHubClientEP->registerTopic("http://websubpubtopic.com");
Parameters
- topic string
The topic to register
Return Type
(TopicRegistrationSuccess | TopicRegistrationError)An error
if an error occurred registering the topic or else ()
deregisterTopic
function deregisterTopic(string topic) returns TopicDeregistrationSuccess | TopicDeregistrationError
Deregisters a topic in a Ballerina WebSub Hub.
1error? deregisterTopic = websubHubClientEP->deregisterTopic("http://websubpubtopic.com");
Parameters
- topic string
The topic to deregister
Return Type
(TopicDeregistrationSuccess | TopicDeregistrationError)An error
if an error occurred un registering the topic or else ()
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.
1error? publishUpdate = websubHubClientEP->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)An error
if an error occurred with the update or else ()
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 error? notifyUpdate = websubHubClientEP->notifyUpdate("http://websubpubtopic.com");
Parameters
- topic string
The topic for which the update occurred
Return Type
(Acknowledgement | UpdateMessageError)An error
if an error occurred with the notification or else ()