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
Isolated Function
Remote Function

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
Isolated Function
Remote Function

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 errorif 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
Isolated Function
Remote Function

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 errorif an error occurred with the update or else ()

notifyUpdate

function notifyUpdate(string topic) returns Acknowledgement | UpdateMessageError
Isolated Function
Remote Function

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 errorif an error occurred with the notification or else ()