SlideShare une entreprise Scribd logo
1  sur  29
#GlobalAzure #ViseoSpirit
Microsoft Azure#GlobalAzure #ViseoSpirit
GAB 2015 LYON ORAGANIZER
LOCAL SPONSORS WORLDWIDE SPONSORS
…
#GlobalAzure #ViseoSpirit
Microsoft Azure#GlobalAzure #ViseoSpirit
• Node
• Open source
– Créé en 2009
– Basé sur le moteur V8
• Application C
– Utilisée en tant que « gestionnaire de requêtes HTTPs » dans
l’exemple d’aujourd’hui
– « Event-driven »
– IO non bloquants
NodeJS
Microsoft Azure#GlobalAzure #ViseoSpirit
Socket.IO
JAVASCRIPT
REALTIME
WEBAPP
BI-DIRECTIONNAL
WEBSOCKETS
UNIFIED API
NODEJS
FALLBACK
EVENT DRIVEN
ASYNCHRONOUS
OPEN SOURCE
BROADCASTING
CLIENT
SERVER
WRAPPER
DATA
AJAX
CROSS PLATFORM
MULTI-CLIENT
Bi-directionnal
communication
Emit message
Broadcasting
Microsoft Azure#GlobalAzure #ViseoSpirit
Application de chat
• Isolation par « room »
• Notifications
• Gravatar
• Fallback pulling
Fil rouge
Microsoft Azure#GlobalAzure #ViseoSpirit
6
Fonctionnement de l’application
connect()
connect
load
peopleInChat
login
img
participantJoined
msg
receive
Login process
Notify users
Chat
loop
Notify users
Microsoft Azure#GlobalAzure #ViseoSpirit
EXÉCUTION LOCALE
Microsoft Azure#GlobalAzure #ViseoSpirit
• DevOps friendly
– Interface intuitive
– x-CLI
• Ouvert
– .Net
– PHP
– Java
– NodeJS
– …
• Déploiement simplifié : git push azure
• CI : hooks Git
Web App
Microsoft Azure#GlobalAzure #ViseoSpirit
• Windows Server
• Serveur web IIS
• Scalabilité automatique
• Pas de root
• Pas d’accès RDP aux machines
Architecture Web App
9
Microsoft Azure#GlobalAzure #ViseoSpirit
• Pas de changement de l’application
• Préparation de l’environnement
– Importation d’un profil de sécurisation
– Exécuté une seule fois
• Selon votre préférence :
– Portail en ligne
– x-CLI
– API Rest
Déploiement
10
Microsoft Azure#GlobalAzure #ViseoSpirit
azure site create gab2015demo --location "West Europe » --git --gitusername
"sescandell"
git push azure local:master
11
Microsoft Azure#GlobalAzure #ViseoSpirit
Activation des websockets
azure site set –w gab2015demo
12
Microsoft Azure#GlobalAzure #ViseoSpirit
EXÉCUTION DEPUIS WEB APP
Microsoft Azure#GlobalAzure #ViseoSpirit
Quels problèmes pour la scalabilité ?
1 1
2 2 2
Les messages ne sont pas envoyés (broadcastés) aux différentes « instances socket.io »
Le stockage des participant est « local » (non partagé)
1
2
Microsoft Azure#GlobalAzure #ViseoSpirit
Architecture ciblée
15
Stockage des participants basé sur Azure
Table Storage (un stockage clé-valeur)
Azure Service Bus service utilisé
comme connecteur inter-scokets
(compatible protocole AMQP)
Point d’entrée de l’application Web App
Agit comme un Load Balancer
Une instance
Microsoft Azure#GlobalAzure #ViseoSpirit
1ère étape : Adapter SocketIO - Service Bus
require(‘azure’);
module.exports = adapter;
function adapter(opts) {
...
var azureServiceBusSender = azure.createServiceBusService();
var azureServiceBusReceiver = azure.createServiceBusService();
function AzureServiceBus(namespace) {
azureServiceBusReceiver.createTopicIfNotExists("default", function(err) {
azureServiceBusReceiver.createSubscription("default",getId(), function(err) {
azureServiceBusReceiver.receiveSubscriptionMessage("default",getId(),this.onmessage.bind(this));
}
})
}
AzureServiceBus.prototype.__proto__ = Adapter.prototype;
AzureServiceBus.prototype.onmessage = function(err, receivedMessage) {
azureServiceBusReceiver.receiveSubscriptionMessage(opts.topic, this.subscriptionId, this.onmessage.bind(this));
args.push(true);
this.broadcast.apply(this, args);
};
16
Microsoft Azure#GlobalAzure #ViseoSpirit
AzureServiceBus.prototype.broadcast = function(packet, opt, remote) {
Adapter.prototype.broadcast.call(this, packet, opt);
if (!remote) {
var message = {
body: msgpack.encode([packet, opt])
};
azureServiceBusSender.sendTopicMessage("default", message);
}
};
return AzureServiceBus;
}
17
Microsoft Azure#GlobalAzure #ViseoSpirit
EXÉCUTION DEPUIS WEB APP AVEC
SOCKET.IO
Microsoft Azure#GlobalAzure #ViseoSpirit
Service Bus & NodeJS… Place à Redis
PubSub
Microsoft Azure#GlobalAzure #ViseoSpirit
Nouvelle architecture ciblée
20
Stockage des participants basé sur
Azure Table Storage (un stockage clé-
valeur)
Azure Redis Cache (via ses
capacités pub/sub)
service utilisé comme connecteur
pour socket.IO
Point d’entrée de l’application Web App
Agit comme un Load Balancer
Une instance
Microsoft Azure#GlobalAzure #ViseoSpirit
1ère étape : Adapter SocketIO - Redis
var redis = require(‘redis’).createClient;
var redisAdapter = require('socket.io-redis');
module.exports = function (app, io) {
...
// Publisher
var redisClientPub = redis(
process.env.REDIS_PORT,
process.env.REDIS_HOST,
{auth_pass: process.env.REDIS_AUTH_PASS}
);
// Subscriber
var redisClientSub = redis(
process.env.REDIS_PORT,
process.env.REDIS_HOST,
{auth_pass: process.env.REDIS_AUTH_PASS, detect_buffers: true}
);
io.adapter(redisAdapter({
pubClient: redisClientPub,
subClient: redisClientSub
}));
21
Microsoft Azure#GlobalAzure #ViseoSpirit
2ème étape : Stockage – Azure Table Storage
var azureStorage = require('azure-storage');
module.exports = function () {
// Service Repository
var ParticipantTableStorage = function () {
var azureTableService = azureStorage.createTableService();
var entGen = azureStorage.TableUtilities.entityGenerator;
var tableName = 'participants';
var partitionKey = "default";
var prefix = process.env.WEBSITE_INSTANCE_ID || 'default';
// If this is the first time the application is launched, let's create the table
azureTableService.createTableIfNotExists(tableName);
return {
22
Microsoft Azure#GlobalAzure #ViseoSpirit
// Retrieve participants count from Store
// We retrieve all participants to show you how to get a users' list
getCount: function(room, callback) {
var query = new azureStorage.TableQuery()
.where('PartitionKey eq ?', partitionKey + room);
azureTableService.queryEntities(tableName, query, null, function(err, result, response){
callback(undefined, result.entries.length);
}.bind(this))
},
// Add a new participant to the store
add: function(participant) {
var entity = {
PartitionKey: entGen.String(partitionKey + participant.room),
RowKey: entGen.String(prefix + participant.id),
username: entGen.String(participant.username),
avatar: entGen.String(participant.avatar),
room: entGen.String(participant.room)
};
azureTableService.insertEntity(tableName, entity)
},
23
Microsoft Azure#GlobalAzure #ViseoSpirit
// Remove a participant from the store
remove: function(participant) {
var entity = {
PartitionKey: entGen.String(partitionKey + participant.room),
RowKey: entGen.String(prefix + participant.id)
};
azureTableService.deleteEntity(tableName, entity);
}
};
return ParticipantTableStorage;
};
24
Microsoft Azure#GlobalAzure #ViseoSpirit
WEB APP / LOCAL / SOCKET IO /
REDIS
Microsoft Azure#GlobalAzure #ViseoSpirit
Pour faire de la
potion magique,
mieux vaut
avoir la bonne
recette
26
Microsoft Azure#GlobalAzure #ViseoSpirit
• Devrait être une règle de base
• Créez des interfaces communes
– Règles d’équipes
– TypeScript
• Injection de dépendances
– Stockage de données
– Système de fichiers
– Gestionnaire d’événement
– … toutes les I/Os
I/O abstraction
27
Microsoft Azure#GlobalAzure #ViseoSpirit
GAB 2015 LYON ORAGANIZER
LOCAL SPONSORS WORLDWIDE SPONSORS
…
#GlobalAzure #ViseoSpirit
Microsoft Azure#GlobalAzure #ViseoSpirit
… je peux essayer d’y
répondre…
Vous avez des questions…

Contenu connexe

En vedette

AWS Webcast - Never Leave a Customer Behind: Scalable Web Apps with AWS
AWS Webcast - Never Leave a Customer Behind: Scalable Web Apps with AWSAWS Webcast - Never Leave a Customer Behind: Scalable Web Apps with AWS
AWS Webcast - Never Leave a Customer Behind: Scalable Web Apps with AWSAmazon Web Services
 
Scalability using Node.js
Scalability using Node.jsScalability using Node.js
Scalability using Node.jsratankadam
 
7 Stages of Scaling Web Applications
7 Stages of Scaling Web Applications7 Stages of Scaling Web Applications
7 Stages of Scaling Web ApplicationsDavid Mitzenmacher
 
Building Scalable Web Applications using Microservices Architecture and NodeJ...
Building Scalable Web Applications using Microservices Architecture and NodeJ...Building Scalable Web Applications using Microservices Architecture and NodeJ...
Building Scalable Web Applications using Microservices Architecture and NodeJ...Mitoc Group
 
Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Ippon
 
2011 02-07-html5-security-v1
2011 02-07-html5-security-v12011 02-07-html5-security-v1
2011 02-07-html5-security-v1Sébastien GIORIA
 
e-Commerce web app Architecture and Scalability
e-Commerce web app Architecture and Scalabilitye-Commerce web app Architecture and Scalability
e-Commerce web app Architecture and ScalabilityAryashree Pritikrishna
 

En vedette (12)

WebSocket avec Java EE 7
WebSocket avec Java EE 7WebSocket avec Java EE 7
WebSocket avec Java EE 7
 
AWS Webcast - Never Leave a Customer Behind: Scalable Web Apps with AWS
AWS Webcast - Never Leave a Customer Behind: Scalable Web Apps with AWSAWS Webcast - Never Leave a Customer Behind: Scalable Web Apps with AWS
AWS Webcast - Never Leave a Customer Behind: Scalable Web Apps with AWS
 
Scalable web architecture
Scalable web architectureScalable web architecture
Scalable web architecture
 
Scalable Web Architecture
Scalable Web ArchitectureScalable Web Architecture
Scalable Web Architecture
 
Scalability using Node.js
Scalability using Node.jsScalability using Node.js
Scalability using Node.js
 
7 Stages of Scaling Web Applications
7 Stages of Scaling Web Applications7 Stages of Scaling Web Applications
7 Stages of Scaling Web Applications
 
Amazon EC2 Masterclass
Amazon EC2 MasterclassAmazon EC2 Masterclass
Amazon EC2 Masterclass
 
Building Scalable Web Applications using Microservices Architecture and NodeJ...
Building Scalable Web Applications using Microservices Architecture and NodeJ...Building Scalable Web Applications using Microservices Architecture and NodeJ...
Building Scalable Web Applications using Microservices Architecture and NodeJ...
 
WebSocket soutenance de stage
WebSocket   soutenance de stageWebSocket   soutenance de stage
WebSocket soutenance de stage
 
Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014
 
2011 02-07-html5-security-v1
2011 02-07-html5-security-v12011 02-07-html5-security-v1
2011 02-07-html5-security-v1
 
e-Commerce web app Architecture and Scalability
e-Commerce web app Architecture and Scalabilitye-Commerce web app Architecture and Scalability
e-Commerce web app Architecture and Scalability
 

Similaire à NodeJS et SocketIO en mode scalable dans le Cloud - GAB 2015

JSS2014 – Haute disponibilité dans Azure
JSS2014 – Haute disponibilité dans AzureJSS2014 – Haute disponibilité dans Azure
JSS2014 – Haute disponibilité dans AzureGUSS
 
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Jean-Laurent de Morlhon
 
[GAB2016] Azure et les Microservices - Jean-Luc Boucho
[GAB2016] Azure et les Microservices - Jean-Luc Boucho[GAB2016] Azure et les Microservices - Jean-Luc Boucho
[GAB2016] Azure et les Microservices - Jean-Luc BouchoCellenza
 
J.L. Boucho, J.Corioland - Azure et les Microservices - Global Azure Bootcamp...
J.L. Boucho, J.Corioland - Azure et les Microservices - Global Azure Bootcamp...J.L. Boucho, J.Corioland - Azure et les Microservices - Global Azure Bootcamp...
J.L. Boucho, J.Corioland - Azure et les Microservices - Global Azure Bootcamp...AZUG FR
 
Déploiement automatisé d'un environnement dans Azure
Déploiement automatisé d'un environnement  dans AzureDéploiement automatisé d'un environnement  dans Azure
Déploiement automatisé d'un environnement dans AzureManon PERNIN
 
Manon Pernin - Déploiement automatisé d’un environnement dans Azure - Global ...
Manon Pernin - Déploiement automatisé d’un environnement dans Azure - Global ...Manon Pernin - Déploiement automatisé d’un environnement dans Azure - Global ...
Manon Pernin - Déploiement automatisé d’un environnement dans Azure - Global ...AZUG FR
 
[Gab2016] Déploiement automatisé d'un environnement dans Azure - Manon Pernin
[Gab2016] Déploiement automatisé d'un environnement dans Azure - Manon Pernin[Gab2016] Déploiement automatisé d'un environnement dans Azure - Manon Pernin
[Gab2016] Déploiement automatisé d'un environnement dans Azure - Manon PerninCellenza
 
Gab2015 Cedric Derue Vincent Thavonekham Approche Devops pour builder une sol...
Gab2015 Cedric Derue Vincent Thavonekham Approche Devops pour builder une sol...Gab2015 Cedric Derue Vincent Thavonekham Approche Devops pour builder une sol...
Gab2015 Cedric Derue Vincent Thavonekham Approche Devops pour builder une sol...Vincent Thavonekham-Pro
 
Architecturez vos applications mobiles avec Azure et Xamarin
Architecturez vos applications mobiles avec Azure et XamarinArchitecturez vos applications mobiles avec Azure et Xamarin
Architecturez vos applications mobiles avec Azure et XamarinThierry Buisson
 
Gab2015 vincent thavonekham_alm_devops_complète_en30_min_et_comment_gérer_la_...
Gab2015 vincent thavonekham_alm_devops_complète_en30_min_et_comment_gérer_la_...Gab2015 vincent thavonekham_alm_devops_complète_en30_min_et_comment_gérer_la_...
Gab2015 vincent thavonekham_alm_devops_complète_en30_min_et_comment_gérer_la_...Vincent Thavonekham-Pro
 
Node.js dans Azure
Node.js dans AzureNode.js dans Azure
Node.js dans AzureMicrosoft
 
Automati(sati)on de votre application Azure
Automati(sati)on de votre application AzureAutomati(sati)on de votre application Azure
Automati(sati)on de votre application AzureMarius Zaharia
 
Gab paris 2015 automatisation
Gab paris 2015   automatisationGab paris 2015   automatisation
Gab paris 2015 automatisationAymeric Weinbach
 
Java dans Windows Azure: l'exemple de Jonas
Java dans Windows Azure: l'exemple de JonasJava dans Windows Azure: l'exemple de Jonas
Java dans Windows Azure: l'exemple de JonasMicrosoft
 
Azugfr 2703 - service fabric
Azugfr   2703 - service fabricAzugfr   2703 - service fabric
Azugfr 2703 - service fabricWilfried Woivre
 
[AzureCamp 24 Juin 2014] Interactions en "temps réel" pour les applications W...
[AzureCamp 24 Juin 2014] Interactions en "temps réel" pour les applications W...[AzureCamp 24 Juin 2014] Interactions en "temps réel" pour les applications W...
[AzureCamp 24 Juin 2014] Interactions en "temps réel" pour les applications W...Microsoft Technet France
 
Machines Virtuelles dans Azure quoi de neuf ?
Machines Virtuelles dans Azure quoi de neuf ?Machines Virtuelles dans Azure quoi de neuf ?
Machines Virtuelles dans Azure quoi de neuf ?Microsoft Décideurs IT
 
Machines Virtuelles dans Azure quoi de neuf ?
Machines Virtuelles dans Azure quoi de neuf ?Machines Virtuelles dans Azure quoi de neuf ?
Machines Virtuelles dans Azure quoi de neuf ?Microsoft Technet France
 
Meetup - Construire des applications serverless avec Azure
Meetup - Construire des applications serverless avec AzureMeetup - Construire des applications serverless avec Azure
Meetup - Construire des applications serverless avec AzureSamir Arezki ☁
 

Similaire à NodeJS et SocketIO en mode scalable dans le Cloud - GAB 2015 (20)

JSS2014 – Haute disponibilité dans Azure
JSS2014 – Haute disponibilité dans AzureJSS2014 – Haute disponibilité dans Azure
JSS2014 – Haute disponibilité dans Azure
 
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
 
[GAB2016] Azure et les Microservices - Jean-Luc Boucho
[GAB2016] Azure et les Microservices - Jean-Luc Boucho[GAB2016] Azure et les Microservices - Jean-Luc Boucho
[GAB2016] Azure et les Microservices - Jean-Luc Boucho
 
J.L. Boucho, J.Corioland - Azure et les Microservices - Global Azure Bootcamp...
J.L. Boucho, J.Corioland - Azure et les Microservices - Global Azure Bootcamp...J.L. Boucho, J.Corioland - Azure et les Microservices - Global Azure Bootcamp...
J.L. Boucho, J.Corioland - Azure et les Microservices - Global Azure Bootcamp...
 
Déploiement automatisé d'un environnement dans Azure
Déploiement automatisé d'un environnement  dans AzureDéploiement automatisé d'un environnement  dans Azure
Déploiement automatisé d'un environnement dans Azure
 
Manon Pernin - Déploiement automatisé d’un environnement dans Azure - Global ...
Manon Pernin - Déploiement automatisé d’un environnement dans Azure - Global ...Manon Pernin - Déploiement automatisé d’un environnement dans Azure - Global ...
Manon Pernin - Déploiement automatisé d’un environnement dans Azure - Global ...
 
[Gab2016] Déploiement automatisé d'un environnement dans Azure - Manon Pernin
[Gab2016] Déploiement automatisé d'un environnement dans Azure - Manon Pernin[Gab2016] Déploiement automatisé d'un environnement dans Azure - Manon Pernin
[Gab2016] Déploiement automatisé d'un environnement dans Azure - Manon Pernin
 
Gab2015 Cedric Derue Vincent Thavonekham Approche Devops pour builder une sol...
Gab2015 Cedric Derue Vincent Thavonekham Approche Devops pour builder une sol...Gab2015 Cedric Derue Vincent Thavonekham Approche Devops pour builder une sol...
Gab2015 Cedric Derue Vincent Thavonekham Approche Devops pour builder une sol...
 
Architecturez vos applications mobiles avec Azure et Xamarin
Architecturez vos applications mobiles avec Azure et XamarinArchitecturez vos applications mobiles avec Azure et Xamarin
Architecturez vos applications mobiles avec Azure et Xamarin
 
Gab2015 vincent thavonekham_alm_devops_complète_en30_min_et_comment_gérer_la_...
Gab2015 vincent thavonekham_alm_devops_complète_en30_min_et_comment_gérer_la_...Gab2015 vincent thavonekham_alm_devops_complète_en30_min_et_comment_gérer_la_...
Gab2015 vincent thavonekham_alm_devops_complète_en30_min_et_comment_gérer_la_...
 
Node.js dans Azure
Node.js dans AzureNode.js dans Azure
Node.js dans Azure
 
Automati(sati)on de votre application Azure
Automati(sati)on de votre application AzureAutomati(sati)on de votre application Azure
Automati(sati)on de votre application Azure
 
Gab paris 2015 automatisation
Gab paris 2015   automatisationGab paris 2015   automatisation
Gab paris 2015 automatisation
 
Java dans Windows Azure: l'exemple de Jonas
Java dans Windows Azure: l'exemple de JonasJava dans Windows Azure: l'exemple de Jonas
Java dans Windows Azure: l'exemple de Jonas
 
Vert.x 3
Vert.x 3Vert.x 3
Vert.x 3
 
Azugfr 2703 - service fabric
Azugfr   2703 - service fabricAzugfr   2703 - service fabric
Azugfr 2703 - service fabric
 
[AzureCamp 24 Juin 2014] Interactions en "temps réel" pour les applications W...
[AzureCamp 24 Juin 2014] Interactions en "temps réel" pour les applications W...[AzureCamp 24 Juin 2014] Interactions en "temps réel" pour les applications W...
[AzureCamp 24 Juin 2014] Interactions en "temps réel" pour les applications W...
 
Machines Virtuelles dans Azure quoi de neuf ?
Machines Virtuelles dans Azure quoi de neuf ?Machines Virtuelles dans Azure quoi de neuf ?
Machines Virtuelles dans Azure quoi de neuf ?
 
Machines Virtuelles dans Azure quoi de neuf ?
Machines Virtuelles dans Azure quoi de neuf ?Machines Virtuelles dans Azure quoi de neuf ?
Machines Virtuelles dans Azure quoi de neuf ?
 
Meetup - Construire des applications serverless avec Azure
Meetup - Construire des applications serverless avec AzureMeetup - Construire des applications serverless avec Azure
Meetup - Construire des applications serverless avec Azure
 

NodeJS et SocketIO en mode scalable dans le Cloud - GAB 2015

  • 2. Microsoft Azure#GlobalAzure #ViseoSpirit GAB 2015 LYON ORAGANIZER LOCAL SPONSORS WORLDWIDE SPONSORS … #GlobalAzure #ViseoSpirit
  • 3. Microsoft Azure#GlobalAzure #ViseoSpirit • Node • Open source – Créé en 2009 – Basé sur le moteur V8 • Application C – Utilisée en tant que « gestionnaire de requêtes HTTPs » dans l’exemple d’aujourd’hui – « Event-driven » – IO non bloquants NodeJS
  • 4. Microsoft Azure#GlobalAzure #ViseoSpirit Socket.IO JAVASCRIPT REALTIME WEBAPP BI-DIRECTIONNAL WEBSOCKETS UNIFIED API NODEJS FALLBACK EVENT DRIVEN ASYNCHRONOUS OPEN SOURCE BROADCASTING CLIENT SERVER WRAPPER DATA AJAX CROSS PLATFORM MULTI-CLIENT Bi-directionnal communication Emit message Broadcasting
  • 5. Microsoft Azure#GlobalAzure #ViseoSpirit Application de chat • Isolation par « room » • Notifications • Gravatar • Fallback pulling Fil rouge
  • 6. Microsoft Azure#GlobalAzure #ViseoSpirit 6 Fonctionnement de l’application connect() connect load peopleInChat login img participantJoined msg receive Login process Notify users Chat loop Notify users
  • 8. Microsoft Azure#GlobalAzure #ViseoSpirit • DevOps friendly – Interface intuitive – x-CLI • Ouvert – .Net – PHP – Java – NodeJS – … • Déploiement simplifié : git push azure • CI : hooks Git Web App
  • 9. Microsoft Azure#GlobalAzure #ViseoSpirit • Windows Server • Serveur web IIS • Scalabilité automatique • Pas de root • Pas d’accès RDP aux machines Architecture Web App 9
  • 10. Microsoft Azure#GlobalAzure #ViseoSpirit • Pas de changement de l’application • Préparation de l’environnement – Importation d’un profil de sécurisation – Exécuté une seule fois • Selon votre préférence : – Portail en ligne – x-CLI – API Rest Déploiement 10
  • 11. Microsoft Azure#GlobalAzure #ViseoSpirit azure site create gab2015demo --location "West Europe » --git --gitusername "sescandell" git push azure local:master 11
  • 12. Microsoft Azure#GlobalAzure #ViseoSpirit Activation des websockets azure site set –w gab2015demo 12
  • 14. Microsoft Azure#GlobalAzure #ViseoSpirit Quels problèmes pour la scalabilité ? 1 1 2 2 2 Les messages ne sont pas envoyés (broadcastés) aux différentes « instances socket.io » Le stockage des participant est « local » (non partagé) 1 2
  • 15. Microsoft Azure#GlobalAzure #ViseoSpirit Architecture ciblée 15 Stockage des participants basé sur Azure Table Storage (un stockage clé-valeur) Azure Service Bus service utilisé comme connecteur inter-scokets (compatible protocole AMQP) Point d’entrée de l’application Web App Agit comme un Load Balancer Une instance
  • 16. Microsoft Azure#GlobalAzure #ViseoSpirit 1ère étape : Adapter SocketIO - Service Bus require(‘azure’); module.exports = adapter; function adapter(opts) { ... var azureServiceBusSender = azure.createServiceBusService(); var azureServiceBusReceiver = azure.createServiceBusService(); function AzureServiceBus(namespace) { azureServiceBusReceiver.createTopicIfNotExists("default", function(err) { azureServiceBusReceiver.createSubscription("default",getId(), function(err) { azureServiceBusReceiver.receiveSubscriptionMessage("default",getId(),this.onmessage.bind(this)); } }) } AzureServiceBus.prototype.__proto__ = Adapter.prototype; AzureServiceBus.prototype.onmessage = function(err, receivedMessage) { azureServiceBusReceiver.receiveSubscriptionMessage(opts.topic, this.subscriptionId, this.onmessage.bind(this)); args.push(true); this.broadcast.apply(this, args); }; 16
  • 17. Microsoft Azure#GlobalAzure #ViseoSpirit AzureServiceBus.prototype.broadcast = function(packet, opt, remote) { Adapter.prototype.broadcast.call(this, packet, opt); if (!remote) { var message = { body: msgpack.encode([packet, opt]) }; azureServiceBusSender.sendTopicMessage("default", message); } }; return AzureServiceBus; } 17
  • 19. Microsoft Azure#GlobalAzure #ViseoSpirit Service Bus & NodeJS… Place à Redis PubSub
  • 20. Microsoft Azure#GlobalAzure #ViseoSpirit Nouvelle architecture ciblée 20 Stockage des participants basé sur Azure Table Storage (un stockage clé- valeur) Azure Redis Cache (via ses capacités pub/sub) service utilisé comme connecteur pour socket.IO Point d’entrée de l’application Web App Agit comme un Load Balancer Une instance
  • 21. Microsoft Azure#GlobalAzure #ViseoSpirit 1ère étape : Adapter SocketIO - Redis var redis = require(‘redis’).createClient; var redisAdapter = require('socket.io-redis'); module.exports = function (app, io) { ... // Publisher var redisClientPub = redis( process.env.REDIS_PORT, process.env.REDIS_HOST, {auth_pass: process.env.REDIS_AUTH_PASS} ); // Subscriber var redisClientSub = redis( process.env.REDIS_PORT, process.env.REDIS_HOST, {auth_pass: process.env.REDIS_AUTH_PASS, detect_buffers: true} ); io.adapter(redisAdapter({ pubClient: redisClientPub, subClient: redisClientSub })); 21
  • 22. Microsoft Azure#GlobalAzure #ViseoSpirit 2ème étape : Stockage – Azure Table Storage var azureStorage = require('azure-storage'); module.exports = function () { // Service Repository var ParticipantTableStorage = function () { var azureTableService = azureStorage.createTableService(); var entGen = azureStorage.TableUtilities.entityGenerator; var tableName = 'participants'; var partitionKey = "default"; var prefix = process.env.WEBSITE_INSTANCE_ID || 'default'; // If this is the first time the application is launched, let's create the table azureTableService.createTableIfNotExists(tableName); return { 22
  • 23. Microsoft Azure#GlobalAzure #ViseoSpirit // Retrieve participants count from Store // We retrieve all participants to show you how to get a users' list getCount: function(room, callback) { var query = new azureStorage.TableQuery() .where('PartitionKey eq ?', partitionKey + room); azureTableService.queryEntities(tableName, query, null, function(err, result, response){ callback(undefined, result.entries.length); }.bind(this)) }, // Add a new participant to the store add: function(participant) { var entity = { PartitionKey: entGen.String(partitionKey + participant.room), RowKey: entGen.String(prefix + participant.id), username: entGen.String(participant.username), avatar: entGen.String(participant.avatar), room: entGen.String(participant.room) }; azureTableService.insertEntity(tableName, entity) }, 23
  • 24. Microsoft Azure#GlobalAzure #ViseoSpirit // Remove a participant from the store remove: function(participant) { var entity = { PartitionKey: entGen.String(partitionKey + participant.room), RowKey: entGen.String(prefix + participant.id) }; azureTableService.deleteEntity(tableName, entity); } }; return ParticipantTableStorage; }; 24
  • 25. Microsoft Azure#GlobalAzure #ViseoSpirit WEB APP / LOCAL / SOCKET IO / REDIS
  • 26. Microsoft Azure#GlobalAzure #ViseoSpirit Pour faire de la potion magique, mieux vaut avoir la bonne recette 26
  • 27. Microsoft Azure#GlobalAzure #ViseoSpirit • Devrait être une règle de base • Créez des interfaces communes – Règles d’équipes – TypeScript • Injection de dépendances – Stockage de données – Système de fichiers – Gestionnaire d’événement – … toutes les I/Os I/O abstraction 27
  • 28. Microsoft Azure#GlobalAzure #ViseoSpirit GAB 2015 LYON ORAGANIZER LOCAL SPONSORS WORLDWIDE SPONSORS … #GlobalAzure #ViseoSpirit
  • 29. Microsoft Azure#GlobalAzure #ViseoSpirit … je peux essayer d’y répondre… Vous avez des questions…