DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. How to Trigger OpenWhisk Actions on Cloudant Databases Changes

How to Trigger OpenWhisk Actions on Cloudant Databases Changes

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

Niklas Heidloff user avatar by
Niklas Heidloff
CORE ·
Jul. 27, 16 · Tutorial
Like (2)
Save
Tweet
Share
2.92K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Database

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • AWS Cloud Migration: Best Practices and Pitfalls to Avoid
  • Real-Time Stream Processing With Hazelcast and StreamNative
  • 5 Factors When Selecting a Database
  • Bye-Bye, Regular Dev [Comic]

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: