際際滷

際際滷Share a Scribd company logo
Community Call - November 2021
Building Real-Time Systems with WebSub
In this presentation
Quick Overview of WebSub Protocol
Real-world Use Case of WebSub
Ballerina WebSub Framework
 Open Protocol for distributed pub/sub communication.
 Based on HTTP webhooks.
 Main Roles:
 Publisher
 Subscriber
 Hub
 Speci鍖cation: https://www.w3.org/TR/websub/
What is WebSub ?
WebSub Cont
Use Case: News Hub
Scenario
 News Hub is a centralized location to which the local journalists
and News channels connect.
 Journalists will publish the news updates to the News Hub.
 News Hub will then distribute the updates to the News channels
who are subscribed to the news feeds of the journalist.
News Hub Cont
Demo
Ballerina WebSub
 In Ballerina, WebSub implementation is divided into two packages:
 WebSub:
 Subscriber
 WebSubHub:
 Hub
 Publisher
Ballerina WebSub: Hub API
public type Service distinct service object {
// Sample POST request hub.mode=register&hub.topic=http://foo.com/bar
// Sample 200 OK response hub.mode=accepted or 200 OK hub.mode=denied&hub.reason=unauthorized
remote function onRegisterTopic(websubhub:TopicRegistration msg)
returns websubhub:TopicRegistrationSuccess|websubhub:TopicRegistrationError|error;
// Sample POST request hub.mode=unregister&hub.topic=http://foo.com/bar
// Sample 200 OK response hub.mode=accepted or 200 OK hub.mode=denied&hub.reason=unauthorized
remote function onDeregisterTopic(websubhub:TopicDeregistration msg)
returns websubhub:TopicDeregistrationSuccess|websubhub:TopicDeregistrationError|error;
// Sample POST request with content type x-www-form-urlencoded hub.mode=publish&hub.topic=http://foo.com/bar
// for other content types such as xml, json and octect-stream hub.mode=publish should be in query string.
// Sample 200 OK response hub.mode=accepted or 200 OK hub.mode=denied&hub.reason=unauthorized
remote function onUpdateMessage(websubhub:UpdateMessage msg)
returns websubhub:Acknowledgement|websubhub:UpdateMessageError|error;
// Sample POST request hub.mode=subscribe&hub.topic=http://foo.com/bar
remote function onSubscription(websubhub:Subscription msg)
returns websubhub:SubscriptionAccepted|websubhub:SubscriptionPermanentRedirect|websubhub:SubscriptionTemporaryRedirect|
websubhub:BadSubscriptionError|websubhub:InternalSubscriptionError|error;
remote function onSubscriptionValidation(websubhub:Subscription msg) returns websubhub:SubscriptionDeniedError|error?;
remote function onSubscriptionIntentVerified(websubhub:VerifiedSubscription msg) returns error?;
// Sample POST request hub.mode=unsubscribe&hub.topic=http://foo.com/bar
remote function onUnsubscription(websubhub:Unsubscription msg)
returns websubhub:UnsubscriptionAccepted|websubhub:BadUnsubscriptionError|websubhub:InternalUnsubscriptionError|error;
remote function onUnsubscriptionValidation(websubhub:Unsubscription msg) returns websubhub:UnsubscriptionDeniedError|error?;
remote function onUnsubscriptionIntentVerified(websubhub:VerifiedUnsubscription msg) returns error?;
}
 WebSub Speci鍖cation: https://www.w3.org/TR/websub/
 Ballerina WebSub Libraries:
 WebSub
 WebSubHub
 Hub Sample:
https://github.com/ballerina-platform/module-ballerina-websubhub/tree/
main/examples/kafka-hub
References
Questions?
Thank you!

More Related Content

Building Real-time Systems with WebSub - Ballerina Community Call - 11/30/2021

  • 1. Community Call - November 2021 Building Real-Time Systems with WebSub
  • 2. In this presentation Quick Overview of WebSub Protocol Real-world Use Case of WebSub Ballerina WebSub Framework
  • 3. Open Protocol for distributed pub/sub communication. Based on HTTP webhooks. Main Roles: Publisher Subscriber Hub Speci鍖cation: https://www.w3.org/TR/websub/ What is WebSub ?
  • 5. Use Case: News Hub Scenario News Hub is a centralized location to which the local journalists and News channels connect. Journalists will publish the news updates to the News Hub. News Hub will then distribute the updates to the News channels who are subscribed to the news feeds of the journalist.
  • 8. Ballerina WebSub In Ballerina, WebSub implementation is divided into two packages: WebSub: Subscriber WebSubHub: Hub Publisher
  • 9. Ballerina WebSub: Hub API public type Service distinct service object { // Sample POST request hub.mode=register&hub.topic=http://foo.com/bar // Sample 200 OK response hub.mode=accepted or 200 OK hub.mode=denied&hub.reason=unauthorized remote function onRegisterTopic(websubhub:TopicRegistration msg) returns websubhub:TopicRegistrationSuccess|websubhub:TopicRegistrationError|error; // Sample POST request hub.mode=unregister&hub.topic=http://foo.com/bar // Sample 200 OK response hub.mode=accepted or 200 OK hub.mode=denied&hub.reason=unauthorized remote function onDeregisterTopic(websubhub:TopicDeregistration msg) returns websubhub:TopicDeregistrationSuccess|websubhub:TopicDeregistrationError|error; // Sample POST request with content type x-www-form-urlencoded hub.mode=publish&hub.topic=http://foo.com/bar // for other content types such as xml, json and octect-stream hub.mode=publish should be in query string. // Sample 200 OK response hub.mode=accepted or 200 OK hub.mode=denied&hub.reason=unauthorized remote function onUpdateMessage(websubhub:UpdateMessage msg) returns websubhub:Acknowledgement|websubhub:UpdateMessageError|error; // Sample POST request hub.mode=subscribe&hub.topic=http://foo.com/bar remote function onSubscription(websubhub:Subscription msg) returns websubhub:SubscriptionAccepted|websubhub:SubscriptionPermanentRedirect|websubhub:SubscriptionTemporaryRedirect| websubhub:BadSubscriptionError|websubhub:InternalSubscriptionError|error; remote function onSubscriptionValidation(websubhub:Subscription msg) returns websubhub:SubscriptionDeniedError|error?; remote function onSubscriptionIntentVerified(websubhub:VerifiedSubscription msg) returns error?; // Sample POST request hub.mode=unsubscribe&hub.topic=http://foo.com/bar remote function onUnsubscription(websubhub:Unsubscription msg) returns websubhub:UnsubscriptionAccepted|websubhub:BadUnsubscriptionError|websubhub:InternalUnsubscriptionError|error; remote function onUnsubscriptionValidation(websubhub:Unsubscription msg) returns websubhub:UnsubscriptionDeniedError|error?; remote function onUnsubscriptionIntentVerified(websubhub:VerifiedUnsubscription msg) returns error?; }
  • 10. WebSub Speci鍖cation: https://www.w3.org/TR/websub/ Ballerina WebSub Libraries: WebSub WebSubHub Hub Sample: https://github.com/ballerina-platform/module-ballerina-websubhub/tree/ main/examples/kafka-hub References