Module event_publisher
choreo/event_publisher
Overview
This is a Choreo client that can be used to publish Choreo events to a configured WebSub hub topic.
Prerequisites
Before using this connector in your Ballerina application, complete the following:
- Configure a topic in WebSub hub and obtain the WebSub hub URL and topic name
Quickstart
To use the Choreo event publisher in your Ballerina application, update the .bal file as follows:
Step 1: Import connector
First, import the choreo/event_publisher
module into the Ballerina project.
import choreo/event_publisher;
Step 2: Create a new connector instance
Create a event_publisher:ClientConfiguration
with the client configurations details, and initialize the connector with it.
event_publisher:ClientConfiguration config = { // Configure the relevant configs } event_publisher:Client publisherClient = check new("<WebSubHubUrl>", "<Topic>", <PollingInterval>, <MaximumQueueLength>, config);
Step 3: Invoke connector operation
-
Now you can use the operations available within the connector. Note that they are in the form of remote operations.
Following is an example on how to publish a Choreo event to the configured WebSub hub topic using the connector.
Publish Choreo event
public function main() returns error? { publisherClient->publishEvent({ orgUuid: "<orgUuid>", timestamp: "<timestamp>", userIdpId: "<userIdpId>", projectId: "<projectId>", action: "<action>", entityType: "<entityType>", info: {}, outcome: event_publisher:SUCCEEDED }); }
-
Use
bal run
command to compile and run the Ballerina program.