Let’s start with Bluemix OpenWhisk 🎉
Wow !!!! wow !!!!wow !! … What is that.. OpenWhisk ?? Serverless computing ?? Events and triggers ?? Hmmm …. Something is happening….. ha ha ha ….😀🤑😎
Ok Guys, be serious. Here I am going to tell you about some real stuff, really really good, personally I used it many times.
OpenWhisk is an OpenSource, an event-driven compute platform service available in Bluemix and you can use it as your own also . See the Project here . It is also referred as Serverless computing or as Function as a Service (FaaS) that runs code in response to events or direct invocations. Basically you write a code and run it when some events happen.
Examples are
- Changes to database records
- IoT sensor readings that exceed a certain temperature
- New code commits to a GitHub repository
- Simple HTTP requests from web or mobile apps etc…
Components
The components of OpenWhisk are –
- Action
- Trigger and
- Rule
An action is linked to a trigger via a rule. Whenever an event happens the trigger will get triggered and the rule will direct invoke the action.
The flow is ,
Event → Trigger → Action .
Creating Actions, Trigger and Rule
The docs are pretty good in Bluemix. You can follow them also.
There are two ways you can create a trigger,
- Create from OpenWhisk Develop console
- From the CLI
OpenWhisk Develop console
- Create one action
2. Create a Trigger
3. Create rule to join the trigger and action
To fire the trigger select the lightning symbol 🌩
5. You can see the results in the OpenWhisk Monitoring dashboard.
OpenWhisk CLI
- Go to the OpenWhisk CLI link. Download CLI and Install it.
- Set your OpenWhisk Namespace and Authorization Key.
- Verify your setup.
- To create an Action you can use the following command,
wsk action create myAction yourNodeJsFile.js
You can write your action in NodeJS, Swift , python etc.
To pass the arguments you can use the -p or – – param commands
For further detail see here.
wsk action create myAction yourNodeJsFile.js -p name "RockStar" -p age "24"
5. T0 create a Trigger use the following command ,
wsk trigger create yourTriggerName
For further details see here.
6. Now time to join the Trigger and Action. Let’s create a Rule
wsk rule create --enable myAction yourTriggerName
For details see here .
Now open another terminal window and run the following command
wsk activation poll
This will show you the details of your action and trigger invocation.
7. To invoke the action ,
wsk trigger fire yourTriggerName
This run your action. You can see the details in the OpenWhisk Monitoring dashboard.
Packages
You can use packages to bundle together a set of related actions, and share them with others.
There are couple of packages provided by bluemix,
- Push Package
- GitHub,
- Slack etc….
Fore details click here
SDKs
Please find the SDKs here,
Examples
There are couple of examples using OpenWhisk,
- https://github.com/ibm-bluemix-push-notifications/Retail-Customer-Feedback-Scenario?cm_mc_uid=28087881939714757475851&cm_mc_sid_50200000=1475781006
- https://github.com/IBM-Swift/BluePic
- https://github.com/IBM-Bluemix/openwhisk-visionapp
- https://github.com/IBM-Bluemix/openwhisk-slackapp
- https://github.com/krook/openfridge
- https://github.com/gconan/BluemixMobileServicesDemoApp
Hope you guys enjoyed it.. Thanks… 😊😃