Created
March 24, 2018 06:03
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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