Over a million developers have joined DZone.

How to Trigger OpenWhisk Actions on Cloudant Databases Changes

DZone's Guide to

How to Trigger OpenWhisk Actions on Cloudant Databases Changes

Learn how to code an OpenWhisk trigger based on changes to your Cloudant database.

· Database Zone
Free Resource

Whether you work in SQL Server Management Studio or Visual Studio, Redgate tools integrate with your existing infrastructure, enabling you to align DevOps for your applications with DevOps for your SQL Server databases. Discover true Database DevOps, brought to you in partnership with Redgate.

I've written about how to write JavaScript Actions for OpenWhisk on Bluemix. Actions can be triggered manually (as described in the previous article) and when certain events occur. Below is a simple sample of how to trigger OpenWhisk actions when documents in Cloudant NoSQL databases are changed or added.

Let's use the same scenario as previously. In a help desk application, you want to translate tickets that have not been written in English to English so that support agents understand. Rather than doing this when tickets are stored or opened, the OpenWhisk action is triggered when new documents are stored in a Cloudant NoSQL database.

The documentation describes how to build this scenario. Essentially you need, in addition to the JavaScript action, a trigger and a rule. Invoke the following commands via the CLI and replace your credentials, namespace, and database name.

wsk property set --auth <yourOpenWhiskUser>:<yourOpenWhiskPassword> --namespace "<yourOpenWhiskNameSpace>"
wsk package bind /whisk.system/cloudant myCloudant -p username '<yourCloudantUser>' -p password '<yourCloudantPassword>' -p host '<yourCloudantHost>'
wsk package list
wsk package get /<yourOpenWhiskNameSpace>/myCloudant
wsk trigger create myCloudantTrigger --feed /<yourOpenWhiskNameSpace>/myCloudant/changes --param <yourCloudantDBName> testdb --param includeDocs true

To see the trigger in action, create a JavaScript action 'hello.js' and a rule:

function main() {
    return {payload: 'Hello world'};

wsk action create hello hello.js
wsk rule create --enable sampleRule myCloudantTrigger hello
wsk activation poll

When you change documents or add them in your Cloudant database, you can see logs in your terminal window and the OpenWhisk dashboard.

It’s easier than you think to extend DevOps practices to SQL Server with Redgate tools. Discover how to introduce true Database DevOps, brought to you in partnership with Redgate

iot app development ,nosql ,cloudant ,openwhisk

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}