Skip to content

Instantly share code, notes, and snippets.

@MaryamZi
Created March 24, 2018 06:03
Show Gist options
  • Save MaryamZi/e405f2e9c63d8e0252c616b91a653a5e to your computer and use it in GitHub Desktop.
Save MaryamZi/e405f2e9c63d8e0252c616b91a653a5e to your computer and use it in GitHub Desktop.
Ballerina WebSub Publisher sample demonstrating bringing up the Ballerina WebSub Hub and publishing directly to the internal hub, and publishing to the hub considering it as a remote hub.
import ballerina/io;
import ballerina/net.websub;
import ballerina/runtime;
endpoint websub:HubClientEndpoint websubHubClientEP {
uri: "http://localhost:9999/websub/hub"
};
function main (string [] args) {
io:println("Starting up the Ballerina Hub Service");
websub:WebSubHub webSubHub = websub:startUpBallerinaHub();
//Allow for subscription
runtime:sleepCurrentWorker(20000);
io:println("Publishing update to internal Hub");
//Publish to the internal Ballerina Hub directly
_ = webSubHub.publishUpdate("http://www.websubpubtopic.com", {"action":"publish","mode":"internal-hub"});
io:println("Publishing update to remote Hub");
//Publish to the internal Ballerina Hub considering it as a remote hub
_ = websubHubClientEP -> publishUpdateToRemoteHub("http://www.websubpubtopic.com",
{"action":"publish","mode":"remote-hub"});
//Allow for notification by the Hub service
runtime:sleepCurrentWorker(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment