Lesson 1: Create an Event Provider using App Builder
In this lesson, we will :
- Create an event provider using an App Builder template
- Register the App as event provider
- Fire Events
- Schedule cron jobs with alarms
Create an event provider using App Builder template
To provide an end-to-end solution, for this Code Lab, we need an event provider to send events to the Journaling API, at a rate that is configurable to help with testing. We will use the OpenWhisk Alarms Package in an App Builder application to create cron jobs.
First, we will create a new App Builder App from a template, following this Code Lab. Be sure to add I/O management API
in the console and choose publish-event
in the CLI template.
Register the app as event provider
To use the CLI to register the app as an event provider, we need to install the Adobe I/O Event CLI plugin, like this:
Copied to your clipboardnpm install -g @adobe/aio-cli-plugin-events
Then follow the steps in this Code Lab.
Fire events and set up to consume them
Now we can arrange to fire events by following the procedure from this Code Lab, making sure to choose Journaling API as the way to consume them.
Scheduling cron jobs with alarms
Follow this CodeLab to fire events automatically by using the runtime alarms package.
Your app.config.yaml
should now look like this:
Copied to your clipboardapplication:actions: actionsweb: web-srcruntimeManifest:packages:my-app:license: Apache-2.0actions:generic:function: actions/generic/index.jsweb: 'yes'runtime: 'nodejs:14'inputs:LOG_LEVEL: debugannotations:require-adobe-auth: truefinal: truepublish-events:function: actions/publish-events/index.jsweb: 'yes'runtime: 'nodejs:14'inputs:LOG_LEVEL: debugapiKey: $SERVICE_API_KEYproviderId: $PROVIDER_IDeventCode: $EVENT_CODEclient_id: $CLIENT_IDclient_secret: $CLIENT_SECRETtechnical_account_email: $TECH_ACCOUNT_EMAILtechnical_account_id: $TECH_ACCOUNT_IDims_org_id: $IMS_ORG_IDprivate_key: $PRIVATE_KEYannotations:final: trueTriggers:everyMin:feed: /whisk.system/alarms/intervalinputs:minutes: 1rules:everyMinRule:trigger: everyMinaction: publish-events
To test the action, execute aio app deploy
in the VSCode terminal. Once the deployment is finished, run aio rt action invoke your-app-name/generic
, and then verify its result and logs using aio rt activation get ID
and aio rt activation logs ID
.
If successful, the event provider should automatically send the events, you should be able to use Postman or cURL to verify that the Journaling API is receiving them.