Object - websub : Hub

Represents the Ballerina WebSub Hub.

Constructor

__init

(string subscriptionUrl, string publishUrl, Listener hubHttpListener)

  • subscriptionUrl string
  • The URL for subscription changes

  • publishUrl string
  • The URL for publishing and topic registration

  • hubHttpListener Listener
  • The http:Listener to which the hub service should be attached

Methods

Stops the started up Ballerina WebSub Hub.
Publishes an update against the topic in the initialized Ballerina Hub.
Registers a topic in the Ballerina Hub.
Unregisters a topic in the Ballerina Hub.
Removes a subscription from the Ballerina Hub, without verifying intent.
Retrieves topics currently recognized by the Hub.
Retrieves details of subscribers registered to receive updates for a particular topic.

Fields

  • subscriptionUrl string
  • The URL for subscription changes

  • publishUrl string
  • The URL for publishing and topic registration

stop

()

returns error?
Stops the started up Ballerina WebSub Hub.
 error? registrationResponse = webSubHub.stop();
  • Return Type

    (error?)
  • An error if hub can't be stoped or else ()

publishUpdate

(string topic, string | xml | json | byte[] | ReadableByteChannel payload, string? contentType)

returns error?
Publishes an update against the topic in the initialized Ballerina Hub.
 error? publishResponse = webSubHub.publishUpdate("http://websubpubtopic.com",{"action": "publish",
 "mode": "internal-hub"});

Parameters

  • topic string
  • The topic for which the update should happen

  • contentType string? (default <string?> ())
  • The content type header to set for the request delivering the payload

  • Return Type

    (error?)
  • An error if the hub is not initialized or does not represent the internal hub or else ()

registerTopic

(string topic)

returns error?
Registers a topic in the Ballerina Hub.
 error? registrationResponse = webSubHub.registerTopic("http://websubpubtopic.com");

Parameters

  • topic string
  • The topic to register

  • Return Type

    (error?)
  • An error if an error occurred with registration or else ()

unregisterTopic

(string topic)

returns error?
Unregisters a topic in the Ballerina Hub.
 error? registrationResponse = webSubHub.unregisterTopic("http://websubpubtopic.com");

Parameters

  • topic string
  • The topic to unregister

  • Return Type

    (error?)
  • An error if an error occurred with unregistration or else ()

removeSubscription

(string topic, string callback)

returns error?
Removes a subscription from the Ballerina Hub, without verifying intent.
 error? registrationResponse = webSubHub.removeSubscription("http://websubpubtopic.com", "removeSubscriptioCallback");

Parameters

  • topic string
  • The topic for which the subscription should be removed

  • callback string
  • The callback for which the subscription should be removed

  • Return Type

    (error?)
  • An error if an error occurred with removal or else ()

getAvailableTopics

()

returns string[]
Retrieves topics currently recognized by the Hub.
 string[] topic = webSubHub.getAvailableTopics();
  • Return Type

    (string[])
  • An array of available topics

getSubscribers

(string topic)

returns SubscriberDetails[]
Retrieves details of subscribers registered to receive updates for a particular topic.
 string[] topic = webSubHub.getSubscribers("http://websubpubtopic.com");

Parameters

  • topic string
  • The topic for which details need to be retrieved