ballerina/websubhub Ballerina library
This module provides APIs for a WebSub Hub service and WebSub Publisher client.
WebSub is a common mechanism for communication between publishers of any kind of web content and their subscribers based on HTTP webhooks. Subscription requests are relayed through hubs, which validate and verify the requests. Hubs then distribute new and updated content to subscribers when it becomes available. WebSub was previously known as PubSubHubbub.
WebSub Hub is an implementation that handles subscription requests and distributes the content to subscribers when the corresponding topic URL has been updated.
WebSub Publisher is an implementation that advertises a topic and hub URL on one or more resource URLs.
Basic flow with WebSub
The subscriber discovers (from the publisher) the topic it needs to subscribe to and the hub(s) that deliver notifications on the updates of the topic.
The subscriber sends a subscription request to one or more discovered hub(s) specifying the discovered topic along with other subscription parameters such as:
- The callback URL to which the content is expected to be delivered.
- (Optional) The lease period (in seconds) the subscriber wants the subscription to stay active.
- (Optional) A secret to use for authenticated content distribution.
The hub sends an intent verification request to the specified callback URL. If the response indicates verification (by echoing a challenge specified in the request) by the subscriber, the subscription is added for the topic at the hub.
The publisher notifies the hub of the updates to the topic and the content to deliver is identified.
The hub delivers the identified content to the subscribers of the topic.
- WebSub HubClient can be used to distribute the published content to subscribers. The current implementation is based on
Ballerina HTTP Client.
- The following is a sample usage for WebSub HubClient.
PublisherClientAPIs are defined by Ballerina and it has no connection with the WebSub specification. As mentioned earlier, even though the WebSub specification extensively discusses the relationship between the subscriber and hub, it does not discuss much the relationship between the publisher and hub.
The following is a sample WebSub Publisher Client.
Return errors from remote methods
- Remote functions in
- For each remote method
errorreturn has a different meaning. Following table depicts the meaning inferred from
errorreturned from all available remote methods.
|Method||Interpreted meaning for Error Return|
|onRegisterTopic||Topic registration failure|
|onDeregisterTopic||Topic de-registration failure|
|onUpdateMessage||Update message error|
|onSubscription||Subscription internal server error|
|onSubscriptionValidation||Subscription validation failure|
|onSubscriptionIntentVerified||Subscription intent verification failure|
|onUnsubscription||Unsubscription internal server error|
|onUnsubscriptionValidation||Unsubscription validation failure|
|onUnsubscriptionIntentVerified||Unsubscription intent verification failure|
Released date: over 1 year ago
Ballerina version: 2201.1.0
Pull count: 10