Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Node.js dans Windows Azure mobile services et web sites

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Chargement dans…3
×

Consultez-les par la suite

1 sur 14 Publicité

Plus De Contenu Connexe

Diaporamas pour vous (20)

Publicité

Similaire à Node.js dans Windows Azure mobile services et web sites (20)

Plus par Microsoft (20)

Publicité

Node.js dans Windows Azure mobile services et web sites

  1. 1. #azurecamp
  2. 2. Node.js • Node.js est un framework opensource événementiel permettant de développer des applications réseau en JavaScript • Créé en 2009 par Ryan Dahl • Utilise le moteur JavaScript V8 de Google et un wrapper C++ optimisé pour gérer les I/O • Tous les requêtes sont asynchrones et s’exécutent sur un seul thread • Construction de services en ligne scalables – Gestion de la concurrence assurée directement par l'OS – Exemples de solution utilisant node.js : Yammer, Yahoo!, WalMart, LinkedIn, eBay,…
  3. 3. Modules node.js • Environnement extrêmement modulaire • Exemples de modules : – “fs”: système de fichier – “net”: réseau, TCP – “crypto”: cryptographie • Support d’un module “http” var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello Worldn'); }).listen(1337, "127.0.0.1"); console.log('Server running at http://127.0.0.1:1337/');
  4. 4. Node.js package manager • L’outil npm est inclus dans le livrable node.js • Catalogue de modules : – http://npmjs.org – 50270 packages (8/12/2013)… connect Standard middleware Sinatra like web framework: routing + templates Real time communication over WebSockets/polling Full-stack MVC (wants to be like Rails) NoSQL data storage In-memory cache jsdom Parse/generate HTML on the server
  5. 5. NODE.JS ET AZURE WEB SITE
  6. 6. Module IISNode : node.js hébergé dans IIS • Gestion des processus • Scalabilité sur des serveurs multicœurs • Auto-update • Access aux logs via HTTP • Intégration avec d’autres types de contenu • Très peu d’impact sur le code node.js • Supervision dans IIS • https://github.com/WindowsAzure/ iisnode
  7. 7. Implémentation d’un « Chat » avec node.js NODE.JS ET AZURE WEB SITE
  8. 8. NODE.JS ET AZURE MOBILE SERVICES
  9. 9. Windows Azure Mobile Services • « Back-end as a Service » pour vos apps mobiles • Étendre les apps web internes à des périphériques mobiles • Construire et déployer rapidement des applications grand public • Un unique back-end pour toutes vos apps • Sur tous les périphériques
  10. 10. Back end « As a Service » • Gestion de données « code first » • Couche de service JSON auto-générée • API REST / SDK pour Win8 / WP8 / IOS / Android / JavaScript • Push / Notification • Unification de l’authentification • Scheduler • Gestion de code source avec Git • …
  11. 11. Support de custom API node.js • Création et exposition de Custom APIs – Implémentées avec Node.js • Support des packages NPM : – Installation dans le référentiel Git associé au site Web – Synchronisation des services mobiles
  12. 12. Custom API et node.js NODE.JS ET AZURE MOBILE SERVICES
  13. 13. Nodejs : outils Microsoft • Nodejs Developper Center – • http://www.windowsazure.com/enus/develop/nodejs Libraries for Azure services – https://github.com/WindowsAzure/azuresdk-for-node • Extension Visual Studio – • https://nodejstools.codeplex.com CmdLets PowerShell – https://github.com/WindowsAzure/azuresdk-tools
  14. 14. © 2012 Microsoft Corporation. Tous droits réservés. Microsoft, Windows et les autres noms de produits sont des marques déposées ou des marques commerciales de Microsoft aux États-Unis et/ou dans d'autres pays. Les informations contenues dans ce document sont fournies uniquement à titre indicatif. Elles représentent l'opinion actuelle de Microsoft Corporation sur les points cités à la date de cette présentation. Microsoft s'adapte aux conditions fluctuantes du marché et ce document ne doit pas être interprété comme un engagement de la part de Microsoft ; de plus, Microsoft ne peut pas garantir la véracité de toute information présentée après la date de la présentation. MICROSOFT EXCLUT TOUTE GARANTIE, EXPRESSE, IMPLICITE OU STATUTAIRE, EN CE QUI CONCERNE CETTE PRÉSENTATION.

Notes de l'éditeur

  • Node s'appuie sur V8, le moteur Javascript de Google utilisé dans Chrome, qui fait partie des moteurs Javascript les plus puissants du marché actuellement. Node va nous permettre de développer très simplement des applications scalables. Comment ? Un petit tour sur le site nous explique son approche : http://nodejs.org/#about. En français et en quelques mots : l'idée est d'utiliser des IO non bloquantes pour gérer toutes les requêtes entrantes, sortantes ainsi que tout le process lié à la requête.Prenons l'exemple du serveur Apache. Chaque requête HTTP entrante se voit allouer un thread. Celui-ci est utilisé pendant toute la durée du traitement de la requête : lecture/écriture en base de données, lecture/écriture dans des fichiers de logs ou autres, exécution de code... Ainsi, si votre code côté serveur fait un accès à la base de données, celui-ci est en attente de la réponse. De plus, durant toute la durée de la requête, le client sera bloqué, en attente de la réponse du serveur.Node et plus globalement les serveurs dits non bloquants (comme Netty ou Deft pour ceux qui tournent sur JVM) adoptent une autre approche. Node n'utilise qu'un seul thread pour gérer les requêtes entrantes. De plus, Node ne propose pas, dans ses API, de fonctions bloquantes. Ainsi, tout notre code est asynchrone. L'avantage immédiat à cela est la simplification à l'extrême de la gestion de la concurrence dans nos applications qui n'est ici plus gérée par le développeur mais directement par l'OS. Concrètement, toutes les fonctions fournies par Node prennent en paramètre un callback. Une fois que la fonction aura terminé son traitement, le callback sera appelé avec le résultat en paramètre et une éventuelle erreur. Ainsi, pendant toute la durée du traitement, le thread sera relâché et pourra être donné à une autre requête pour effectuer un autre traitement. Nous sommes donc face à un système évènementiel. Et Javascript est un très bon choix de langage du fait que l'on peut programmer de manière fonctionnelle avec celui-ci. Les callbacks dans tous les sens, nous connaissons très bien avec des librairies comme jQuery qui nous habituent depuis déjà quelques temps à ce type de développement.Les fonctions fournies par Node prennent en paramètre un callback. Une fois que la fonction aura terminé son traitement, le callback sera appelé avec le résultat en paramètre.Pendant toute la durée du traitement, le thread sera relâché et pourra être donné à une autre requête pour effectuer un autre traitement. Un seul thread = une seule stack allouée en mémoire
  • node.js process lifetime managementnode.js process scalability across multiple coresSide-by side with other content typesnode-inspector built-in for debugging, logs accessible over HTTPRestart node.js process on app changeDeveloper-friendly errorsTomasz Janczuk isworking on the iisnodeprojectlately. You mightthinkthat Windows and nodedon'tbelongtogether. "That'sjustwrong! What are theythinking? I thought IIS was all about .NET?" Well, youmayrecall I spokeatCodeMash a few years back on IIS7 and PHP and did a screencastshowing how IIS7, PHP and FastCGIcould push manythousands of requests a second. The IIS folks, the Windows folks, the Azure folks, want to make sure everythingrunswell on Windows. Remember, wesellWindows, soit's good if itdoesmanythingswell. ;)Whybothergettingnode to run on IIS? Tomasz saysit best:Some of the advantages of hosting node.js applications in IIS using the iisnode module as opposed to self-hosting node.exe processesinclude:Process management. The iisnode module takes care of lifetime management of node.exe processesmakingit simple to improveoverallreliability. You don’t have to implement infrastructure to start, stop, and monitor the processes. Scalability on multi-core servers. Since node.exe is a single threadedprocess, itonlyscales to one CPU core. The iisnode module allowscreation of multiple node.exe processes per application and load balances the HTTP trafficbetweenthem, thereforeenabling full utilization of a server’s CPU capacitywithoutrequiringadditional infrastructure code from an application developer. Auto-update. The iisnode module ensuresthatwhenever the node.js application isupdated (i.e. the script file has changed), the node.exe processes are recycled. Ongoingrequests are allowed to gracefully finish executionusing the old version of the application, while all new requests are dispatched to the new version of the app. Access to logs over HTTP. The iisnode module providesaccess the output of the node.exe process (e.g. generated by console.log calls) via HTTP. This facilityis key in helpingyoudebug node.js applications deployed to remote servers. Side by sidewithother content types. The iisnode module integrateswith IIS in a waythatallows a single web site to contain a variety of content types. For example, a single site cancontain a node.js application, static HTML and JavaScript files, PHP applications, and ASP.NET applications. This enableschoosing the best tools for the job at hand as well progressive migration of existing applications. Minimal changes to node.js application code. The iisnode module enableshosting of existing HTTP node.js applications withvery minimal changes. Typically all thatisrequiredis to change the listedaddress of the HTTP server to one provided by the iisnode module via the process.env.PORTenvironment variable. Integrated management experience. The issnode module isfullyintegratedwith IIS configuration system and uses the sametools and mechanism as other IIS components for configuration and maintenance. In addition to benefitsspecific to the iisnode module, hosting node.js applications in IIS allows the developer to benefitfrom a range of IIS features, amongthem:port sharing (hosting multiple HTTP applications over port 80) security (HTTPS, authentication and authorization) URL rewriting compression cachingloggingThese are all compelling, but the mostinteresting bit here, in my opinion, isintegration. The iisnode module is a proper IIS module, justlike ASP.NET and PHP. This meansyoucan have a single websitethat has multiple kinds of content. Restatedfromabove:For example, a single site cancontain a node.js application, static HTML and JavaScript files, PHP applications, and ASP.NET applications.Sometimes folks freak out when I sayyoucan have an ASP.NET WebFormsapp and a ASP.NET MVC app in the sameAppPool as a "hybrid." Frankly, Dear Reader, people don'tevenrealize the power and flexibility of IIS. Whenyou plug in something new likenode but runit the wayyourunotherthingsitinherits all the coolness of the outer container, in this case, IIS.
  • Mobile apps  Another use case is to use the Cloud like a “mother ship” with which mobiles and tablets can hook up for computing resources.  With Windows Azure Mobile Services, you can streamline common development tasks like structuring storage, integrating push notifications and configuring user authentication. Mobile Services fully supports Windows Store, Windows Phone 8, iOS, Android and HTML5 development. Windows Azure Mobile Services makes it faster and easier to build dynamic mobile apps that scale.  Mobile Services streamlines common development tasks like storing data in the cloud, authenticating users, and sending push notifications. We take care of the infrastructure so you can focus on what matters—user experience. -Extend internal web apps to mobile devices: With an increasingly mobile workforce, your employees need to be able to both access and interact with important internal applications from any device.  With Mobile Services, you can extend internal web apps to a variety of mobile devices and enable your workforce to stay connected no matter where they are.  You can deliver that experience even if you have sensitive data that needs to stay on-premises behind a firewall.   -Quickly build and deploy consumer facing apps: Mobile Services supplies the infrastructure you need to stand up a consumer facing mobile app in minutes.  You can also easily work with your favorite APIs like Twilio for adding voice/SMS or SendGrid for sending email to further accelerate development. -Land your app on any platform or device: Mobile Services provides out of the box support for iOS, Android, Windows Store, Windows Phone 8, HTML5, and Windows Phone 7 apps. We give you the choice of developing native apps using the SDK for each platform, mobile web apps that run on any platform, or using Xamarin.iOS and Xamarin.Android to write native apps for iOS and Android in C#. 
  • Mobile apps  Another use case is to use the Cloud like a “mother ship” with which mobiles and tablets can hook up for computing resources.  With Windows Azure Mobile Services, you can streamline common development tasks like structuring storage, integrating push notifications and configuring user authentication. Mobile Services fully supports Windows Store, Windows Phone 8, iOS, Android and HTML5 development. Windows Azure Mobile Services makes it faster and easier to build dynamic mobile apps that scale.  Mobile Services streamlines common development tasks like storing data in the cloud, authenticating users, and sending push notifications. We take care of the infrastructure so you can focus on what matters—user experience. -Extend internal web apps to mobile devices: With an increasingly mobile workforce, your employees need to be able to both access and interact with important internal applications from any device.  With Mobile Services, you can extend internal web apps to a variety of mobile devices and enable your workforce to stay connected no matter where they are.  You can deliver that experience even if you have sensitive data that needs to stay on-premises behind a firewall.   -Quickly build and deploy consumer facing apps: Mobile Services supplies the infrastructure you need to stand up a consumer facing mobile app in minutes.  You can also easily work with your favorite APIs like Twilio for adding voice/SMS or SendGrid for sending email to further accelerate development. -Land your app on any platform or device: Mobile Services provides out of the box support for iOS, Android, Windows Store, Windows Phone 8, HTML5, and Windows Phone 7 apps. We give you the choice of developing native apps using the SDK for each platform, mobile web apps that run on any platform, or using Xamarin.iOS and Xamarin.Android to write native apps for iOS and Android in C#. 
  • create and expose Custom APIs fromyour Mobile Service backend, and easilypublishthem to your Mobile clients withouthaving to associatethemwith a data table. This capabilityenables a whole set of new scenarios – including the ability to workwith data sources otherthan SQL Databases (for example: Table Services or MongoDB), broker calls to 3rd party APIs, integratewith Windows Azure Queues or Service Bus, workwith custom non-JSON payloads (e.g. Windows Periodic Notifications), route client requests to services back on-premises (e.g. with the new Windows Azure BizTalk Services), or simplyimplementfunctionalitythatdoesn’t correspond to a databaseoperation.  The custom APIs canbewritten in server-side JavaScript (using Node.js) and can use Node’s NPM packages.  Wewillalsobeadding support for custom APIs writtenusing .NET in the future as well.
  • npm install azureBlob storageTable storageQueuesService BusService Runtime(more coming)Examples: www.windowsazure.com/en-us/develop/nodejs/

×