nodejs @ acs

21
Node ACS Mauro Parra-Miranda [email protected]

Upload: mauro-parra-miranda

Post on 24-May-2015

1.311 views

Category:

Technology


1 download

DESCRIPTION

Intro to the use of nodejs in ACS.

TRANSCRIPT

Page 2: NodeJS @ ACS

Agenda

Introduction

NodeJS

Features

Examples

Page 3: NodeJS @ ACS

IntroductionFixed set of features in the ACS: checkins, post in social networks, user administration, etc.

Customers with needs out of that universe were a kind of lost, since they have to provide their own webservices for custom stuff.

Customers are not that good in setting up webservices that escalate; or setup servers in general.

Page 4: NodeJS @ ACS

SolutionACS was already providing a nice escalating infrastructure; the natural step was to extend that service to a custom small/micro programs.

Node JS was the selected technology to do the bridge between the customer and the ACS, with super escalating power (vitamins added).

Think of ACS as a Meta Cloud Services Provider, with zero server configuration time.

Page 5: NodeJS @ ACS

NodeJS“Node.js is an evented I/O framework for the V8 JavaScript engine. It is intended for writing scalable network programs such as web servers.” - Wikipedia.

Who uses NodeJS? - Yammer, Proxlet, Bocoup, Yahoo, Walmart, Appcelerator :-)

Niceties: Parallel execution, event driven, mongodb support, etc.

Page 6: NodeJS @ ACS

FeaturesCluster, crypto, dns, events, file system, http, https, modules, OS, Path, Process, readline, query strings, mongodb, timers, strings, tls/ssl, udp/datagram, utilities, zlib.

You can use modules from the nodejs world, such as: http://blog.nodejitsu.com/6-must-have-nodejs-modules

xml2js: if you are using old webservices, you can easily transform xml responses into javascript objects with this module. Think SOAP and stuff.

Page 7: NodeJS @ ACS

Setup

install (from terminal in mac): $ sudo npm install -g acs

setup (from terminal in mac):$ acs login

Create a new app (from terminal in mac):$ acs new myappthis will create a directory myapp w/ your newapp

Page 8: NodeJS @ ACS

Edit your app

Go to your directory myapp. Inside you will find myapp.js. Edit and add this:api.index = function(req, res) { res.text('Hello, world!'); logger.info('This is an info message. ' + new Date()); }

Save it.

Page 9: NodeJS @ ACS

Running your app locally

acs run -d myapp

Go to http://localhost:8080 to see your app running locally.

If you are running jenkins, your app will use other port (Jenkins uses 8080 by default), so you will likely end in 8081 port.

Page 10: NodeJS @ ACS

Running your app in ACS

acs publish -d myapp

You will see your app running at http://<appid>.cloudservices.appcelerator.com

It’s like having a Heroku in appc.

Page 11: NodeJS @ ACS

ServiceThe app now has one service (or a single endpoint) called api.index. The args are “Express framework” Request and Response Objects

I.e. we are running express. Check more about it here: http://expressjs.com/

You can add more services, with “acs add”.

acs add <name>

You will expose this new service in two ways. One public at: <app_url>/<name> and one in the code by api.<name>

Page 12: NodeJS @ ACS

ModulesYou can use any nodejs modules within your app, using npm.

You will need to list the modules you are using (dependencies) in the package.json file. So, when you deploy the app (either locally or in the ACS infrastructure), the modules will be installed in your running instance.

Besides the Node modules, you will have the logger function for log and the builtin ACS library for calling the ACS services.

Page 13: NodeJS @ ACS

Big fat example

Check this call to the ACS login - user level

Call to ACS Places

You can call any of the functions in ACS api!

Page 14: NodeJS @ ACS

Real problem - EscalateEscalate - This is the real issue. You will need something that will escalate properly and easily.

Now, with NodeJS and ACS, you can escalate your webservices. Which, usually, will depend on a database.

You now will have access to MongoDB - i.e., this next generation non-relational db.

Think of mongodb as a db that will store objects instead of rows and columns - forget the excel type of order, get into a objects.

Page 15: NodeJS @ ACS

Setup mongodb

Create an app.

Add mongodb as dependency in the package.json:

"dependencies": { "mongodb": ">=1.1.6" },

Page 16: NodeJS @ ACS

Open connection to mongodb

Page 17: NodeJS @ ACS

Insert a record

Page 18: NodeJS @ ACS

Query a record

Page 19: NodeJS @ ACS

Mongoose

Module to provide ORM-alike features to NodeJS. This is, will abstract the objects from your Javascript to MongoDB records easily.

https://github.com/learnboost/mongoose/

Page 20: NodeJS @ ACS

NodeJS - how we escale?You have a service, with a single point of entry (like url/service).

In order to not block the server, you will need a request handler (worker) that will actually do the job, freeing the service to continue into listen mode.

the request handler will actually implement the steps to do the processing - this is how you escalate.

Forkity Fork!** sorry, i used to be a linux guy - fork processes