SlideShare a Scribd company logo
1 of 24
Download to read offline
Building an Activity Stream Engine on
                         Cloud Foundry with Node.js
                         Hands-on Lab

                         By Monica Wilkinson




                         © 2012 VMware, Inc. All rights reserved

Friday, January 27, 12
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
                                                                                           2

Friday, January 27, 12
Agenda
      1.Overview of Cloud Foundry
      2.What is Activity Streams ?
      3.Building an Activity Stream Engine




                                CONFIDENTIAL
                                               3

Friday, January 27, 12
About Cloud Foundry                              The first Open PaaS

                         Multi(n) Languages, Frameworks,
                                 Services & Clouds
                                  Open Source




                                     CONFIDENTIAL
                                                                      4

Friday, January 27, 12
Getting Started on Cloud Foundry




                                      CONFIDENTIAL
                                                            5

Friday, January 27, 12
STEP 1 - Get a Cloud Foundry Account

    https://my.cloudfoundry.com/signup/NodeSummit




                           CONFIDENTIAL
                                                     6

Friday, January 27, 12
STEP 2 - Login to Cloud Foundry


      •sudo gem
        install vmc
      •vmc login
        <username>




                         CONFIDENTIAL
                                        7

Friday, January 27, 12
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
                                                                 8

Friday, January 27, 12
What is Activity Streams ?




                                   CONFIDENTIAL
                                                      9

Friday, January 27, 12
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
                                                                               10

Friday, January 27, 12
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 reserved

Friday, January 27, 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
                                                                               12

Friday, January 27, 12
Building an Activity Streams Engine




                                    CONFIDENTIAL
                                                           13

Friday, January 27, 12
What should we use to store Activities ?


 Key-Value               Column               Document      Graph




      Redis,             Cassandra,              MongoDB   Neo4J
      Riak               HBase




                                      CONFIDENTIAL
                                                                    14

Friday, January 27, 12
Mongo DB schema-less documents are perfect
   for Activities

 Key-Value               Column           Document           Graph




                                                 MongoDB
                                                 (so easy)




                                  CONFIDENTIAL
                                                                     15

Friday, January 27, 12
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
                                                                              16

Friday, January 27, 12
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
                                                                                       17

Friday, January 27, 12
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
                                                                     18

Friday, January 27, 12
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
                                                                  19

Friday, January 27, 12
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
                                                              20

Friday, January 27, 12
Exposing the Engine as Service




                                      CONFIDENTIAL
                                                          21

Friday, January 27, 12
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
                                                                 22

Friday, January 27, 12
http://asms.cloudfoundry.com




                         CONFIDENTIAL
                                        23

Friday, January 27, 12
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 reserved

Friday, January 27, 12

More Related Content

Similar to Node Summit 2012

The spring 32 update final
The spring 32 update finalThe spring 32 update final
The spring 32 update finalJoshua Long
 
Cloud Camp Chicago Dec 2012 Slides
Cloud Camp Chicago Dec 2012 SlidesCloud Camp Chicago Dec 2012 Slides
Cloud Camp Chicago Dec 2012 SlidesRyan Koop
 
Cloud Camp Chicago Dec 2012 - All presentations
Cloud Camp Chicago Dec 2012 - All presentationsCloud Camp Chicago Dec 2012 - All presentations
Cloud Camp Chicago Dec 2012 - All presentationsCloudCamp Chicago
 
NCA GTUG 2012 - Cloud is such stuff as dreams are made on
NCA GTUG 2012 - Cloud is such stuff as dreams are made onNCA GTUG 2012 - Cloud is such stuff as dreams are made on
NCA GTUG 2012 - Cloud is such stuff as dreams are made onPatrick Chanezon
 
Cloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinCloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinJoshua Long
 
Cloud Architecture Tutorial - Why and What (1of 3)
Cloud Architecture Tutorial - Why and What (1of 3) Cloud Architecture Tutorial - Why and What (1of 3)
Cloud Architecture Tutorial - Why and What (1of 3) Adrian Cockcroft
 
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
Drupal + HTML5 + CSS3 + JS = Rich Internet ApplicationDrupal + HTML5 + CSS3 + JS = Rich Internet Application
Drupal + HTML5 + CSS3 + JS = Rich Internet ApplicationDrupalcampAtlanta2012
 
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
Drupal + HTML5 + CSS3 + JS = Rich Internet ApplicationDrupal + HTML5 + CSS3 + JS = Rich Internet Application
Drupal + HTML5 + CSS3 + JS = Rich Internet ApplicationAppnovation Technologies
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom UsageJoshua Long
 
Chicago from the Cloud
Chicago from the CloudChicago from the Cloud
Chicago from the CloudWAN-IFRA
 
Semantic Web Landscape 2009
Semantic Web Landscape 2009Semantic Web Landscape 2009
Semantic Web Landscape 2009LeeFeigenbaum
 
Continuously Design your Continuous Deployment
Continuously Design your Continuous DeploymentContinuously Design your Continuous Deployment
Continuously Design your Continuous DeploymentMichael Elder
 
Getting Started Developing with Platform as a Service
Getting Started Developing with Platform as a ServiceGetting Started Developing with Platform as a Service
Getting Started Developing with Platform as a ServiceCloudBees
 
Java Microservices HJUG
Java Microservices HJUGJava Microservices HJUG
Java Microservices HJUGLana Kalashnyk
 
Open stack for open source private cloud 20120425-shanghai
Open stack for open source  private cloud  20120425-shanghaiOpen stack for open source  private cloud  20120425-shanghai
Open stack for open source private cloud 20120425-shanghaiOpenCity Community
 
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012Patrick Chanezon
 
A Tour of Ruby On Rails
A Tour of Ruby On RailsA Tour of Ruby On Rails
A Tour of Ruby On RailsDavid Keener
 

Similar to Node Summit 2012 (20)

MongoUK 2012
MongoUK 2012MongoUK 2012
MongoUK 2012
 
The spring 32 update final
The spring 32 update finalThe spring 32 update final
The spring 32 update final
 
Cloud Camp Chicago Dec 2012 Slides
Cloud Camp Chicago Dec 2012 SlidesCloud Camp Chicago Dec 2012 Slides
Cloud Camp Chicago Dec 2012 Slides
 
Cloud Camp Chicago Dec 2012 - All presentations
Cloud Camp Chicago Dec 2012 - All presentationsCloud Camp Chicago Dec 2012 - All presentations
Cloud Camp Chicago Dec 2012 - All presentations
 
NCA GTUG 2012 - Cloud is such stuff as dreams are made on
NCA GTUG 2012 - Cloud is such stuff as dreams are made onNCA GTUG 2012 - Cloud is such stuff as dreams are made on
NCA GTUG 2012 - Cloud is such stuff as dreams are made on
 
Cloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and VaadinCloud Foundry, Spring and Vaadin
Cloud Foundry, Spring and Vaadin
 
Cloud Architecture Tutorial - Why and What (1of 3)
Cloud Architecture Tutorial - Why and What (1of 3) Cloud Architecture Tutorial - Why and What (1of 3)
Cloud Architecture Tutorial - Why and What (1of 3)
 
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
Drupal + HTML5 + CSS3 + JS = Rich Internet ApplicationDrupal + HTML5 + CSS3 + JS = Rich Internet Application
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
 
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
Drupal + HTML5 + CSS3 + JS = Rich Internet ApplicationDrupal + HTML5 + CSS3 + JS = Rich Internet Application
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
 
Extending Spring for Custom Usage
Extending Spring for Custom UsageExtending Spring for Custom Usage
Extending Spring for Custom Usage
 
Chicago from the Cloud
Chicago from the CloudChicago from the Cloud
Chicago from the Cloud
 
Semantic Web Landscape 2009
Semantic Web Landscape 2009Semantic Web Landscape 2009
Semantic Web Landscape 2009
 
Continuously Design your Continuous Deployment
Continuously Design your Continuous DeploymentContinuously Design your Continuous Deployment
Continuously Design your Continuous Deployment
 
Getting Started Developing with Platform as a Service
Getting Started Developing with Platform as a ServiceGetting Started Developing with Platform as a Service
Getting Started Developing with Platform as a Service
 
Java Microservices HJUG
Java Microservices HJUGJava Microservices HJUG
Java Microservices HJUG
 
Open stack for open source private cloud 20120425-shanghai
Open stack for open source  private cloud  20120425-shanghaiOpen stack for open source  private cloud  20120425-shanghai
Open stack for open source private cloud 20120425-shanghai
 
Cloud foundry and openstackcloud
Cloud foundry and openstackcloudCloud foundry and openstackcloud
Cloud foundry and openstackcloud
 
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
Cloud Foundry, the Open Platform as a Service - Oscon - July 2012
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
A Tour of Ruby On Rails
A Tour of Ruby On RailsA Tour of Ruby On Rails
A Tour of Ruby On Rails
 

Recently uploaded

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Recently uploaded (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Node Summit 2012

  • 1. Building an Activity Stream Engine on Cloud Foundry with Node.js Hands-on Lab By Monica Wilkinson © 2012 VMware, Inc. All rights reserved Friday, January 27, 12
  • 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 2 Friday, January 27, 12
  • 3. Agenda 1.Overview of Cloud Foundry 2.What is Activity Streams ? 3.Building an Activity Stream Engine CONFIDENTIAL 3 Friday, January 27, 12
  • 4. About Cloud Foundry The first Open PaaS Multi(n) Languages, Frameworks, Services & Clouds Open Source CONFIDENTIAL 4 Friday, January 27, 12
  • 5. Getting Started on Cloud Foundry CONFIDENTIAL 5 Friday, January 27, 12
  • 6. STEP 1 - Get a Cloud Foundry Account  https://my.cloudfoundry.com/signup/NodeSummit CONFIDENTIAL 6 Friday, January 27, 12
  • 7. STEP 2 - Login to Cloud Foundry •sudo gem install vmc •vmc login <username> CONFIDENTIAL 7 Friday, January 27, 12
  • 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 8 Friday, January 27, 12
  • 9. What is Activity Streams ? CONFIDENTIAL 9 Friday, January 27, 12
  • 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 10 Friday, January 27, 12
  • 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 reserved Friday, January 27, 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 12 Friday, January 27, 12
  • 13. Building an Activity Streams Engine CONFIDENTIAL 13 Friday, January 27, 12
  • 14. What should we use to store Activities ? Key-Value Column Document Graph Redis, Cassandra, MongoDB Neo4J Riak HBase CONFIDENTIAL 14 Friday, January 27, 12
  • 15. Mongo DB schema-less documents are perfect for Activities Key-Value Column Document Graph MongoDB (so easy) CONFIDENTIAL 15 Friday, January 27, 12
  • 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 16 Friday, January 27, 12
  • 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 17 Friday, January 27, 12
  • 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 18 Friday, January 27, 12
  • 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 19 Friday, January 27, 12
  • 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 20 Friday, January 27, 12
  • 21. Exposing the Engine as Service CONFIDENTIAL 21 Friday, January 27, 12
  • 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 22 Friday, January 27, 12
  • 23. http://asms.cloudfoundry.com CONFIDENTIAL 23 Friday, January 27, 12
  • 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 reserved Friday, January 27, 12