Building an Activity Stream Engine on                         Cloud Foundry with Node.js                         Hands-on ...
About Monica Wilkinson                                 Loves the web and data portability.                         Develop...
Agenda      1.Overview of Cloud Foundry      2.What is Activity Streams ?      3.Building an Activity Stream Engine       ...
About Cloud Foundry                              The first Open PaaS                         Multi(n) Languages, Framework...
Getting Started on Cloud Foundry                                      CONFIDENTIAL                                        ...
STEP 1 - Get a Cloud Foundry Account    https://my.cloudfoundry.com/signup/NodeSummit                           CONFIDENT...
STEP 2 - Login to Cloud Foundry      •sudo gem        install vmc      •vmc login        <username>                       ...
STEP 3 - Push your code to Cloud Foundry     vmc push         • Detects runtime automatically.         • In addition if yo...
What is Activity Streams ?                                   CONFIDENTIAL                                                 ...
http://activityStrea.ms    Activity Streams is a simple open specification used to describe social      actions around th...
Actor -> Monica                                                                    Verb -> Pinned(Bookmarked)             ...
What is an Activity Stream Engine ?    An activity stream engine allows you to publish events and subscribe to      event...
Building an Activity Streams Engine                                    CONFIDENTIAL                                       ...
What should we use to store Activities ? Key-Value               Column               Document      Graph      Redis,     ...
Mongo DB schema-less documents are perfect   for Activities Key-Value               Column           Document           Gr...
About MongoDB   1. No-SQL database                        development : {   2. Stores JSON-style                          ...
Step 1- Build the persistence Model        var MediaLinkHash = {           duration: Number,           height: Number,    ...
Step 1- Persistence Model       var ActivitySchema = new Schema({           id: {type: String},           verb: {type: Str...
Step 2 - Expose helpers for the queries    The most important is to be able to list the activities in     descending orde...
How do we make our engine faster and more   scalable ?    Add support for PubSub    In a PubSub model as soon as an even...
Exposing the Engine as Service                                      CONFIDENTIAL                                          ...
Using Socket.io    Server Side:     • Subscribe to a Stream     • When there is a new event send it to the client as JSON...
http://asms.cloudfoundry.com                         CONFIDENTIAL                                        23Friday, January...
Thank You - Questions ?                         Cloud Foundry Activity Streams Libraries are at:                          ...
Upcoming SlideShare
Loading in …5
×

Node Summit 2012

3,383 views

Published on

Activity Streams on Cloud Foundry

Published in: Technology
1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total views
3,383
On SlideShare
0
From Embeds
0
Number of Embeds
435
Actions
Shares
0
Downloads
30
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Node Summit 2012

  1. 1. Building an Activity Stream Engine on Cloud Foundry with Node.js Hands-on Lab By Monica Wilkinson © 2012 VMware, Inc. All rights reservedFriday, January 27, 12
  2. 2. About Monica Wilkinson Loves the web and data portability. Developer Advocate @ Cloud Foundry 12 years development experience. Last 5 years in Social Web Open Web Standards Advocate Contact Me: @ciberch mwilkinson@vmware.com CONFIDENTIAL 2Friday, January 27, 12
  3. 3. Agenda 1.Overview of Cloud Foundry 2.What is Activity Streams ? 3.Building an Activity Stream Engine CONFIDENTIAL 3Friday, January 27, 12
  4. 4. About Cloud Foundry The first Open PaaS Multi(n) Languages, Frameworks, Services & Clouds Open Source CONFIDENTIAL 4Friday, January 27, 12
  5. 5. Getting Started on Cloud Foundry CONFIDENTIAL 5Friday, January 27, 12
  6. 6. STEP 1 - Get a Cloud Foundry Account  https://my.cloudfoundry.com/signup/NodeSummit CONFIDENTIAL 6Friday, January 27, 12
  7. 7. STEP 2 - Login to Cloud Foundry •sudo gem install vmc •vmc login <username> CONFIDENTIAL 7Friday, January 27, 12
  8. 8. STEP 3 - Push your code to Cloud Foundry vmc push • Detects runtime automatically. • In addition if you have manifest.yml vmc will read: • App Name • App Instances • Services to bind to App •Demo CONFIDENTIAL 8Friday, January 27, 12
  9. 9. What is Activity Streams ? CONFIDENTIAL 9Friday, January 27, 12
  10. 10. http://activityStrea.ms  Activity Streams is a simple open specification used to describe social actions around the web.  The goal of Activity Streams is data portability  Some publishers of Activity Streams: Socialcast, MySpace, Facebook and G+  The default format is JSON but Atom is also supported. The JSON format was added after we saw some initial limitations with JSON  Core concepts are: Actor, Verb, Object and Target CONFIDENTIAL 10Friday, January 27, 12
  11. 11. Actor -> Monica Verb -> Pinned(Bookmarked) Object -> Rosa Parks’ Bio Page Target -> Female Leaders Board Source -> Pinterest Published -> MLK Day 2012 © 2012 VMware, Inc. All rights reservedFriday, January 27, 12
  12. 12. What is an Activity Stream Engine ?  An activity stream engine allows you to publish events and subscribe to events.  Many activity stream engine support aggregation of events via Streams.  Many activity stream engines support fanning out activities to subscribers.  Many activity stream engines tailor the stream to the reader providing Key Stats and Contextual Info. Example: Monica with 1000 followers or Bank of America established in 1989 CONFIDENTIAL 12Friday, January 27, 12
  13. 13. Building an Activity Streams Engine CONFIDENTIAL 13Friday, January 27, 12
  14. 14. What should we use to store Activities ? Key-Value Column Document Graph Redis, Cassandra, MongoDB Neo4J Riak HBase CONFIDENTIAL 14Friday, January 27, 12
  15. 15. Mongo DB schema-less documents are perfect for Activities Key-Value Column Document Graph MongoDB (so easy) CONFIDENTIAL 15Friday, January 27, 12
  16. 16. About MongoDB 1. No-SQL database development : { 2. Stores JSON-style tools: many, documents with language_support: superb, embedded documents = agility: high 3. Horizontally scalable }, production: { 4. Full Indexing Support speed: fast 5. Open Source so great fault_tolerance: true ORMs and drivers. scalability: high CONFIDENTIAL 16Friday, January 27, 12
  17. 17. Step 1- Build the persistence Model var MediaLinkHash = {         duration: Number,         height: Number,         width: Number,         url: String     };     var ActivityObjectHash = {        id: {type: String},        image: MediaLinkHash,        displayName: {type: String},        summary: {type: String},        content: {type: String},        url: {type:String},        author: {type: ObjectId, ref: activityObject},        published: {type: Date, default: Date.now},        updated: {type: Date, default: Date.now},        objectType: {type: String},        attachments: [{type: ObjectId, ref: activityObject}],        upstreamDuplicates: [String],        downstreamDuplicates: [String]     };     var ActivityObjectSchema = new Schema(ActivityObjectHash)     this.ActivityObject = mongoose.model(activityObject, ActivityObjectSchema); CONFIDENTIAL 17Friday, January 27, 12
  18. 18. Step 1- Persistence Model     var ActivitySchema = new Schema({         id: {type: String},         verb: {type: String},         url: {type: String},         title: {type: String},         content: {type: String},         icon: MediaLinkHash,         object: ActivityObjectHash,         actor: ActivityObjectHash,         target: {type: ObjectId, ref: activityObject},         published: { type: Date, default: Date.now},         updated: { type: Date, default: Date.now},         inReplyTo: {type: ObjectId, ref: activity}     });     this.Activity = mongoose.model(activity, ActivitySchema);     return this; }; CONFIDENTIAL 18Friday, January 27, 12
  19. 19. Step 2 - Expose helpers for the queries  The most important is to be able to list the activities in descending order by published time.  It is also important to hydrate any objects for which we have references  With Mongoose you can do:   this.getActivityStream = function(n, fx) { Activity.find().sort(published, descending).limit(n).populate(target).run (fx);     }  More at: https://github.com/cloudfoundry-samples/ activity-streams-mongoose CONFIDENTIAL 19Friday, January 27, 12
  20. 20. How do we make our engine faster and more scalable ?  Add support for PubSub  In a PubSub model as soon as an event is published it gets sent to all the subscribers.  The Publisher doesn’t know who the subscribers are, it simply knows where to publish.  Redis has nice support for Pub Sub http://redis.io/topics/ pubsub CONFIDENTIAL 20Friday, January 27, 12
  21. 21. Exposing the Engine as Service CONFIDENTIAL 21Friday, January 27, 12
  22. 22. Using Socket.io  Server Side: • Subscribe to a Stream • When there is a new event send it to the client as JSON  Client Side • Add support to publish activities to the Stream • Change the client rendering to use ActivityStrea.ms  Benefits • Richer messaging • Activity Syndication CONFIDENTIAL 22Friday, January 27, 12
  23. 23. http://asms.cloudfoundry.com CONFIDENTIAL 23Friday, January 27, 12
  24. 24. Thank You - Questions ? Cloud Foundry Activity Streams Libraries are at: https://github.com/organizations/cloudfoundry-samples http://cloudfoundry.com Questions: @cloudfoundry - @ciberch or mwilkinson@vmware.com © 2012 VMware, Inc. All rights reservedFriday, January 27, 12

×