NS study8 DDD Microservices Azuer Service Fabric

  • Published on
    03-Mar-2017

  • View
    426

  • Download
    4

Transcript

PowerPoint

2016/07/06NSStudy No.8www.nextscape.net1C# Azure Service Fabric DDD Azure

MicroservicesMicroservicesDDDDomain-Driven DesignDDDAzure Service Fabricwww.nextscape.net2

2

Twitter:@takashiuesaka44Azure(Microsoft MVP for Microsoft Azure)ScrumDDD2016de:code 2016 DDD & Azure Service Fabric NS Study No.6 Azure IoTHub IT Azure Machine Learning SANSAN DDD2015FEST2015 (Channel9)MSxNextscape Azure Machine LearningDevelopers Summit 2015QCon 2015CloudDays2015 3 BP2015930ITProAzure Machine Learningwww.nextscape.net3

3

www.nextscape.net4

200241015001

163-07222-7-122F03-5325-1301()

4

www.nextscape.net520122014 2013 Microsoft Worldwide Partner Award Sitecore Of The Year Asia 2013Cloud Partner of the Year Best Japanese Site3 Microsoft Azure

www.nextscape.net6NO MUSIC, NO LIFE.250TOWER RECORDS ONLINECMSSitecore20101100PV20144205https://www.sitecore.net/ja-jp/customers/e-commerce/towerrecords.aspxTV powerd by BeeTV d powered by BeeTVMicrosoft Azurehttp://special.nikkeibp.co.jp/as/201207/mpncompetency/cs01.html400EC32CMS

Microservices

7

Microserviceswww.nextscape.net8SOASOASOA

SOAPWCF----------------------------SOARESTDDD

8

MicroservicesDDD

9

MicroservicesDDDwww.nextscape.net10DDDDDD

DDDSOA

DDDDDD

10

Domain-Driven Design

DDDDDDDDDHOWDDDDDD

11

DDDwww.nextscape.net12

12

DDDwww.nextscape.net13IT

DDDwww.nextscape.net14

DDDwww.nextscape.net15

DDDDDDwww.nextscape.net16DDD

16

www.nextscape.net17

17

www.nextscape.net18DDD

www.nextscape.net19

19

www.nextscape.net20

20

www.nextscape.net21

21

www.nextscape.net22https://www.infoq.com/jp/articles/ddd-contextmapping_jpWeb

()UDDU

22

www.nextscape.net23Modularity and Domain Driven Design; a killer combination?http://www.slideshare.net/aca_it/modularity-ddd

fromto

www.nextscape.net24

www.nextscape.net25

DDDwww.nextscape.net26DDD and Hexagonal architecturehttp://tindaloscode.blogspot.jp/2013/11/ddd-and-hexagonal-architecture.htmlPortAndAdapter

LayerApplicationLayer

PortClient PortClient PortPortPortHTMLWeb GadgetRIAViewerWeb APIESBinboundRDBMSIn-memoryObject storeESBoutboundLayerLayer

ESBEnterprise Service BusSOA26

DDD

27

DDDwww.nextscape.net28

www.nextscape.net29

www.nextscape.net30

Azure Service FabricMSDN

31

Azure Service Fabricwww.nextscape.net32PaaS1Wikipedia1

www.nextscape.net33ExeExeExeExeExeExeExeExeExeExe

www.nextscape.net34ExeExeExeExeExeExeExeExeExeExeExe

www.nextscape.net35ExeExeExeExeExeExeExeExeExeExeExe

www.nextscape.net36ExeExeExeExeExeExeExeExeExeExe

Azure Service Fabricwww.nextscape.net372Exe, JavaServiceFabricSDK

ServiceFabric2

Azure Service FabricMSDN1Reliable ActorExewww.nextscape.net38

Service FabricService FabricLinuxAzure

Azure Service Fabricwww.nextscape.net39MicroServicesPaaS

Azure Service Fabricwww.nextscape.net40Acitor

Service Fabric

Microsoft Azure

Service Fabric SDk

www.nextscape.net41

Service Fabricwww.nextscape.net42

Service FabricLinux

42

Service Fabric SDKwww.nextscape.net43ServiceFabricSDKReliable ServiceReliable Actor Service ServiceExeService FabricStatelessServiceStatefullService

StatelessServiceStafefullService

43

StatelessServicewww.nextscape.net44

Stateless Servicewww.nextscape.net45

StatelessService

StatefullServiceStatelessServiceStatefullServiceTask RunAsync(CancellationToken cancellationToken)Task OnOpenAsync(CancellationToken cancellationToken)Task OnCloseAsync(CancellationToken cancellationToken)void OnAbort()IEnumerable CreateServiceInstanceListeners()Override

RunASyncOK1while(true)WorkerRoleOnAbort, OnCloseASync, OnOpenASyncRunASync

45

Service Fabricwww.nextscape.net46

StatelessService

RunASync, OnOpenASync, OnCloseASync, OnAbort

MyServiceICommunicationListenerMyListener

protected override IEnumerable CreateServiceInstanceListeners(){ return new ServiceInstanceListener[] { new ServiceInstanceListener(serviceContext => new MyListener ()) };}Task OpenAsync(CancellationToken cancellationToken)Task CloseAsync(CancellationToken cancellationToken)void Abort()

1http1httpPort3tcp

Open,Close,AbortOpenASynchttp://:port/

OpenASync

FabricRuntimFabricRuntime.GetNodeContext().IPAddressOrFQDN

46

WebIISOWINVisual StudioService Fabric WebAPIMSDN

www.nextscape.net47StatelessService

Startupvoid ConfigureApp(IAppBuilder appBuilder)protected override IEnumerable CreateServiceInstanceListeners(){ return new ServiceInstanceListener[] { new ServiceInstanceListener( serviceContext => new OwinCommunicationListener( Startup.ConfigureApp, serviceContext, ServiceEventSource.Current, "ServiceEndpoint")) };}

ICommunicationListener

OwinCommunicationListenerTask OpenAsync(CancellationToken cancellationToken)

OpenASyncURIhttps://azure.microsoft.com/ja-jp/documentation/articles/service-fabric-reliable-services-communication-webapi/MSDNURL

WCFwww.nextscape.net48ICommunicationListenerNuget

https://azure.microsoft.com/ja-jp/documentation/articles/service-fabric-reliable-services-communication-wcf/MSDNURL

StatelessService

WCFwww.nextscape.net49WCFCalculatorclass Calculator : ICalculator{ public Task Add(int value1, int value2) { return Task.FromResult(value1 + value2); }} internal sealed class WcfHostStateless : StatelessService{ private ICalculator _calculator; public WcfHostStateless(StatelessServiceContext context) : base(context) { this._calculator = new Calculator(); }

protected override IEnumerable CreateServiceInstanceListeners(){ return new ServiceInstanceListener[] { new ServiceInstanceListener(serviceContext => new WcfCommunicationListener( wcfServiceObject:this._calculator, serviceContext:base.Context, endpointResourceName: "WcfServiceEndpoint", listenerBinding: WcfUtility.CreateTcpListenerBinding() )) };}

WCFwww.nextscape.net50ServiceUriWCFUrifabric:///WCF

private void CallWcf(StatelessServiceContext context, string endpointName){ var binding = WcfUtility.CreateTcpClientBinding();

IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault();

var wcfClientFactory = new WcfCommunicationClientFactory (clientBinding: binding, servicePartitionResolver: partitionResolver);

var calculatorServiceCommunicationClient = new WcfCommunicationClient( wcfClientFactory, new Uri("fabric:/ServiceFabricWcf/WcfHostStateless"), ServicePartitionKey.Singleton);

var result = calculatorServiceCommunicationClient.InvokeWithRetryAsync( client => client.Channel.Add(2, 3)).Result;} this.CallWcf(this.Context, "WcfServiceEndpoint");RunAsyncCallWcfWcfEndpoint

51

www.nextscape.net52

http://www.irasutoya.com/www.nextscape.net53

NS Study

5Microservices13MicroservicesEOSLMicroservicesMicroservicesMicroservicesMicroservicesDDD2MicroServiceSOAWFDDDDDD620DDD

DDDDDD26

Azure Service Fabric310ActorServiceApplication

11

www.nextscape.net54

Service Fabric APIStateless Service Program.cs

ServiceManifest.xmlTypeMyServiceTypeServiceFabricMyService.cs

MyServiceTypeServiceManifest.xmlMyServiceServiceManifest.xmlprivate static void Main(){ ServiceRuntime.RegisterServiceAsync("MyServiceType", context => new MyService (context)).GetAwaiter().GetResult();

ServiceFabricMyService.exeVS

internal sealed class MyService : StatelessService{ protected override IEnumerable CreateServiceInstanceListeners() { }

protected override async Task RunAsync(CancellationToken cancellationToken) { WorkerRole }

protected override void OnAbort() { } protected override Task OnCloseAsync(CancellationToken cancellationToken) { } protected override Task OnOpenAsync(CancellationToken cancellationToken) { }

}

www.nextscape.net55

StatefulCollection() () (ACID )IReliableQueue, IReliableDictionary2StateManagerStatefulServiceStatefulCollectioninternal sealed class MyStatefulService : StatefulService{ protected override async Task RunAsync(CancellationToken cancellationToken) { // ReliableDictionary var myDictionary = await this.StateManager.GetOrAddAsync("myDictionary");

// using (var tx = this.StateManager.CreateTransaction()) { // ReliableDictionary var result = await myDictionary.TryGetValueAsync(tx, "Counter");

// ReliableDictionary await myDictionary.AddOrUpdateAsync(tx, "Counter", 0, (key, value) => ++value);

// CommitAsync // await tx.CommitAsync(); } }}www.nextscape.net56

Stateful12PrimarySecondary2Primary1SecondaryPrimaryPrimarySecondaryPrimarySecondaryPrimary

www.nextscape.net57