Microservices für .Net Entwickler · Asp.Net Core Windows Container Guest Executable Reliable Actor API Reliable Service API Service Fabric On-Premise Azure Windows Server Linux

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

  • Microservices für .Net Entwickler

    26.06.2017 Developer Week 2017 Bilder: www.dreamstime.com

    Tobias Meier, BridgingIT GmbH, Lead Softwarearchitekt Microsoft

  • Wir bringen Dinge zusammen

    Standort Nürnberg

    Königtorgraben 11

    90402 Nürnberg

    Standort Zug/Schweiz

    Baarerstraße 14

    CH-6300 Zug

    Standort Mannheim

    N7, 5-6

    68161 Mannheim

    Standort Karlsruhe

    Rüppurrer Straße 4

    76137 Karlsruhe

    Standort Stuttgart

    Marienstraße 17

    70178 Stuttgart

    Standort München

    Riesstraße 12

    80992 München

    Standort Frankfurt

    Solmsstraße 4

    60486 Frankfurt

    Standort Köln

    Martinstraße 3

    50667 Köln

    Copyright © BridgingIT GmbH | Autor: Tobias Meier | Juni 2017 | www.bridging-it.de

    Lead Softwarearchitekt Microsoft

    http://blog.bridging-it.de/author/Tobias.Meier [email protected] @bitTobiasMeier

    Tobias Meier

  • Agenda

    Herausforderungen und Status quo

    Was sind Microservices ?

    Microservices in .Net

    Entwickeln für Service Fabric

    Vorstellen der Beispielanwendung

  • Monolitische Architektur

    Schichten Architektur

    Skalierung über Hardware

    bzw. VMs DB Locks

    Wächst und wächst …

  • Microservice

  • Microservice-Architektur

    Kleine, unabhängige Services

    Eigener Prozess

    Leichtgewichtige Kommunikation

    Unabhängige, automatisierte Installation

    Verschiedene Technologien und/oder Programmiersprachen möglich

    Unabhängige Datenspeicherung

    Minimaler zentralisierter Managementaufwand

  • Microservice = SOA Done right

    = SOA + DDD + Patterns

    Patterns: Autonome Services, Bounded Context, Event Driven Design, Continuous Delivery, …

  • „Ok, dann teilen wir unseren Monolithen in hunderte Services auf.“

  • Auch verteilte Anwendungen haben ihre

    Fallstricke …

  • Komplexität der Verteilung

    Abhängigkeiten untereinander

    Daten-Konsistenz

    Ermittlung des Bounded Context

    Höherer Entwicklungsaufwand

    Netzwerklatenz

    Versionierung von Schnittstellen

    Welche Version ist installiert ?

    Testbarkeit ist schwerer

    Orchestrierung

  • The Art of Scalability: Scale Cube

    http://theartofscalability.com/

    X: Horizontale Skalierung

    Y: F

    un

    ktio

    na

    le S

    ka

    lieru

    ng

  • Microservices mit C#

    .Net Web API

    Azure Functions:

    AWS Lambda

    Container Services:

    Service

  • Microservices mit C#

    .Net Web API

    Azure Functions: https://functions.azure.com/try

    AWS Lambda https://aws.amazon.com/de/visualstudio/

    Container Services:

    Service Fabric

    Function as a Service (FaaS)

    https://functions.azure.com/tryhttps://aws.amazon.com/de/visualstudio/

  • Microservices mit C#

    .Net Web API

    Azure Functions: https://functions.azure.com/try

    AWS Lambda https://aws.amazon.com/de/visualstudio/

    Container Services: u.a. http://aka.ms/acs

    Service Fabric

    Function as a Service (FaaS)

    https://functions.azure.com/tryhttps://aws.amazon.com/de/visualstudio/http://aka.ms/acs

  • Aufbau Service Fabric

    Microservice

    WebAppOwin

    Microservice

    WebAppAsp.Net Core

    Windows Container

    Guest Executable

    Reliable Actor API Reliable Service API

    Service Fabric

    On-Premise Azure

    Windows Server LinuxWindows Server Linux

    Microservice

    Java

    Microservice

    Hosted in Container

    Naming Service

  • Aufbau Service Fabric

    Microservice

    WebAppOwin

    Microservice

    WebAppAsp.Net Core

    Windows Container

    Guest Executable

    Reliable Actor API Reliable Service API

    Service Fabric

    On-Premise Azure

    Windows Server LinuxWindows Server Linux

    Microservice

    Java

    Microservice

    Hosted in Container

    Naming Service

    Build 2017: Roadmap

    Reliable Actor und Reliable Services in Container verwendbar.

    State-Management für Container

  • Service Fabric: Platform as a service

    Microsoft nutzt Service Fabric:

    Azure Sql DatabaseCortanaCosmos DbEvent Hubs IoT-SuiteSkype for BusinessDynamicsPower BI Intune

  • Service Fabric: Platform as a service

    Microsoft nutzt Service Fabric:

    Azure Sql DatabaseCortanaCosmos DbEvent Hubs IoT-SuiteSkype for BusinessDynamicsPower BI Intune

    Build 2017

    30 % of Azure cores run Service Fabric

    Designed for mission critical tier 1 workloads

  • Stateless Service

    Zustandsloser Service

    Typisches Modell für heutige Webanwendungen

    Daten können extern gehalten werdenSql Datenbank

    DocumentDB

    Azure Storage

  • Service Fabrik SDK installieren

    Visual Studio immer als Admin starten

  • Beispiel ModuleHello World

    Web API ProjektDWXDemo

    Lokales Cluster

  • Service Cluster Lokal

    Entwicklungs-Cluster

    http://localhost:19080/

    http://localhost:19080/

  • Stateful Service

    Zustand bleibt auch nach Neustart erhalten

    Synchronisation über Replicas

    StateManager

    Reliable Collection

    Transaktionen

  • Reliable Service API

    Stateless oder Stateful Service

    Naming Service

    Zugriff auf Service Fabric APIs

    Modelle zum Data-Upgrade

    Zuverlässigkeit

    Reliability

    Verfügbarkeit

    Availability

    Skalierbarkeit

    Scalability

    Beständigkeit

    Consistency

  • Beispiel ModuleDemo Stateful Service

  • Reliable Collectionsusing (var tx = StateManager.CreateTransaction()){

    var members = await StateManager.GetOrAddAsync("members");

    await members.AddOrUpdateAsync(tx, person.Email, person, (key, p) => person);

    person.Email = person.Email.ToUpper();

    await tx.CommitAsync();}

    ToUpper() wird NICHT übernommen

  • Reliable Collectionsusing (var tx = StateManager.CreateTransaction()){

    var members = await StateManager.GetOrAddAsync("members");

    person.Email = person.Email.ToUpper();

    await members.AddOrUpdateAsync(tx, person.Email, person, (key, p) => person);

    await tx.CommitAsync();}

    ToUpper() wird übernommen

  • Tipp: Objekte sollten Immutable sein

    Private Setter

    System.Collections.Immutable

    https://www.nuget.org/packages/System.Collections.Immutable

    https://www.nuget.org/packages/System.Collections.Immutable

  • Immutable Collection[DataContract]public sealed class PersonData{public PersonData(string name, IEnumerable emails){this.Name = name;Emails = (emails== null) ? ImmutableList.Empty :emails.ToImmutableList();

    }[DataMember] public readonly string Name;[DataMember] public IEnumerable Emails { get; private set; }

    [OnDeserialized]private void OnDeserialized(StreamingContext context){Emails = Emails.ToImmutableList();

    }}

  • Reliable Actors

  • Actor: Lifecycle

    Automatisch erzeugt

    Identifikation über eine Id

    Automatische Verteilung im Cluster

    Akteuere können „schlafen gelegt“ werden

    Können manuell explizit gelöscht werden

  • Actor erzeugen

    var data = …

    var photoActorId = ActorId.CreateRandom();

    var client = ActorProxy.Create(photoActorId,

    "fabric:/PhotoAward/PhotoActorService" );

    await client.SetPhoto(data, CancellationToken.None);

  • Actor löschen

    var svc = (IActorService) this.ActorService;

    await svc.DeleteActorAsync(this.Id, cancellationToken);

  • Actor: Timer

    Wrapper um .Net Timer

    RegisterTimer

    Nach Beendigung des Callbacks startet das nächste Zeitfenster

    Unregister Timer

    „Schlafen gelegte“ Actors erhalten keinen Timeraufruf

  • Actor: Reminder

    Reminders werden auch zu bestimmten Zeitpunkten ausgelöst

    Sie werden IMMER ausgelöst

    public class ToDoListActor : Actor, IPhotoAwardActor, IRemindable{

    public Task ReceiveReminderAsync(string name, byte[] context, TimeSpan dueTime, TimeSpan period){

    if (name=="Abgabetermin"){

    int amountToPay = BitConverter.ToInt32(context, 0);System.Console.WriteLine("Please pay your cell phone bill of ${0}!", amountToPay);

    }return Task.FromResult(true);

    }}

  • Beispiel ModuleDemo: Statefull Actor

  • Update

    Application Version erhöhen

    Code Version erhöhen

    Evtl. Data Version erhöhen

  • Continuous Delivery

    TFS 2017 und TFS Online Eigene ServiceFabric Tasks für Build

    und Release:

    Versionsnummer setzen

    Deployment

  • 1. Endpunkt im TFS definieren

  • 2. Continous Delivery erzeugen …

  • 3. Build Template bearbeiten

  • 3. Build Template bearbeiten: NPM install

  • 4. Build Template bearbeiten: Angular-CLI-Output verarbeiten

  • 5. Release Template

  • Beispielanwendung

    Benutzer kann sich registrieren

    Thumbnails von Fotos werden angezeigt

    Fotos können hochgeladen und kommentiert werden.

    AdministrationsanwendungÜber http//localhost aufrufbar:

    Backup / Restore http://localhost:8208/api/administration/backup/nameOfBackup

    http://localhost:8208/api/administration/restore/nameOfBackup

    https://github.com/bitTobiasMeier/PhotoAwardDemo

    http://localhost:8208/api/administration/backup/nameOfBackuphttp://localhost:8208/api/administration/restore/nameOfBackuphttps://github.com/bitTobiasMeier/PhotoAwardDemo

  • Service Fabric

    PhotoAward.Platform

    StatelessWebApi und

    Fileserver

    PhotoAward.MemberManagement

    Statefull Service

    PhotoAward.PhotoManagement

    Statefull Service

    PhotoAward.Thumbnail

    Stateless Service

    PhotoAward.PhotoActor

    Actor Service

    PhotoAward.MemberActor

    Actor Service

    Me

    mb

    erA

    ctor.

    Inte

    rfaces

    Ph

    oto

    Acto

    r.

    Inte

    rfaces

    Ph

    oto

    Db

    .

    Inte

    rfaces

    Me

    mb

    erM

    anagem

    ent.

    Inte

    rfaces

    Ph

    oto

    Man

    agemen

    t.

    Inte

    rfaces

    Ports: 8443

    Co

    nso

    le.C

    lien

    tP

    ho

    toA

    ward

    Ap

    p(A

    ngu

    lar2)

    API-Gateway

    Azu

    re C

    ogn

    itive Service

    s

    PhotoAward.PhotoDb

    Stateless Service

    Thu

    mb

    naiil.

    Inte

    rfaces

    Asynchrone Aufrufe Asynchrone Aufrufe aus einem Reminder,

    werden im Fehlerfall wiederholt.

    Co

    smo

    sDb

    PhotoAward.Administration

    Platform

    StatelessWebApi

  • Beispiel ModuleBeispielapplikation

    PhotoAwardDemo

  • Microservices für .Net Entwickler

    Service Fabric bietet leistungsfähige Plattform mit

    Z-Scale

    Alles hat seinen Preis

    Continous Delivery von Anfang an

    Clustererstellung skripten

    Clusterplanung ist komplex

  • Microservices für .Net Entwickler

    Out of Scope

    Authentication und Authorization

    Unit Testing

    Partitionierung der Daten

    (Vortrag von Daniel Marbach)

    Backup / Restore

    Docker

  • Understanding Azure –a guide vor developers

    http://aka.ms/adg

    Service Fabric SDK

    http://aka.ms/ServiceFabricSDK

    Case Studies

    https://blogs.msdn.microsoft.com/azureservicefabric/

    tag/case-study/

    Beispielanwendung

    https://github.com/bitTobiasMeier/PhotoAwardDemo

    Blog

    http://blog.bridging-it.de/author/Tobias.Meier

    http://aka.ms/ServiceFabricSDKhttp://aka.ms/ServiceFabricSDKhttps://blogs.msdn.microsoft.com/azureservicefabric/tag/case-study/https://github.com/bitTobiasMeier/PhotoAwardDemohttp://blog.bridging-it.de/author/Tobias.Meier

  • Vielen Dank

    Email: [email protected] Twitter: @bITTobiasMeier

    Blog: http://blog.bridging-it.de/author/Tobias.Meier

    Bilder: www.dreamstime.com