Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Building .NET Microservices

2.850 visualizaciones

Publicado el

SpringOne Platform 2016
Speakers: Kevin Hoffman; Advisory Solutions Architect, Pivotal & Chris Umbel; Advisory Architect, Pivotal

With the advent of ASP.NET Core, developers can now build cross-platform microservices in .NET. We can build services on the Mac, Windows, or Linux and deploy anywhere--most importantly to the cloud.

In this session we'll talk about Cloud Native .NET, building .NET microservices, and deploying them to the cloud. We'll build services that participate in a robust ecosystem by consuming OSS servers such as Spring Cloud Configuration Server and Eureka. We'll also show how these .NET microservices can take advantage of circuit breakers and be automatically deployed to the cloud via CI/CD pipelines.

Publicado en: Tecnología
  • Sé el primero en comentar

Building .NET Microservices

  1. 1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Building .NET Microservices Kevin Hoffman & Chris Umbel @KevinHoffman , @ChrisUmbel
  2. 2. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ About Us 2 @KevinHoffman @ChrisUmbel
  3. 3. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3
  4. 4. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Agenda • Create ASP.NET Core project • Add middleware • Add controller • Inject a Repository • Communicate with a Database • Consume Spring Cloud Config Server • Participate in Service Discovery • All on a Mac • No Windows were harmed for any of these demos! 😮 4
  5. 5. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ASP.NET Web and Service Development Today • Maintaining Windows servers carrying pre-cloud baggage • Traditional MSI-based Windows Server Application Installs • Production deploy with RDP, run MSI! • Deploy via Active Directory Group Policy • Maintain and Configure IIS • Servers are long-lived, bloated pets. • Extremely difficult for 3-Rs security (Rotate, Repave, Repair) • Tightly coupled, closed ecosystem • Mostly closed source • All-or-nothing monolithic framework 5
  6. 6. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The Future is Core • Modern, immutable, dependency-vendored artifact deploy • Modular - import only the frameworks you need! • Easier to maintain Linux servers • NO IIS. • That’s right… NO IIS. • Linux servers are cloud ready. • Easier to treat servers as disposable • Open Source • Did we mention that there is no IIS? • Core on Windows is ideal stepping-stone from legacy to pure Core • Core is Microsoft’s stated future direction for .NET 6
  7. 7. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s in ASP.NET Core? • .NET Core • Cross-platform, open-source runtime • Bare-bones, minimum required to start an app • Application types: Console, Web (ASP.NET Core), UWP • Part of .NET Foundation http://www.dotnetfoundation.org/projects • Implementation of lessons learned since ASP.NET 1.0 released 14 years ago • Yes, we’re THAT OLD. " • MVC Framework (optional module, like everything else) • Server-side rendering/templating • Routing • Microservices 7
  8. 8. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hello Core World • dotnet new • dotnet restore • dotnet run 8 https://www.microsoft.com/net/core
  9. 9. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hello, World! 9 DEMO
  10. 10. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ASP.NET Middleware • Components added to request pipeline to handle requests & responses • Build pipeline with Run, Map, and Use methods. • Common middleware: • Serving static files • Error handling • Authentication • MVC (Routing and Processing) • Code can defer, branch, or terminate pipeline 10
  11. 11. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Adding Middleware 11 DEMO
  12. 12. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ RESTful Routes • Route pattern at Class level • [Route(“api/[controller]”)] • Route pattern on HTTP methods • [HttpGet(“{id}")] • Automatic deserialization • [FromBody]Monster monster • Return ActionResult, supports async keyword for async actions • Explicit • Can add global context roots (useful in PCF) • http://bit.ly/2ap5gGF • Mix-and-Match 12
  13. 13. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Dependency Injection • Scoped services • Global services • Configuration system • Middleware • Default IOC container included, but can be customized • Autofac • Pattern should be familiar to Spring developers 13
  14. 14. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Dependency Injection & Controllers 14 DEMO
  15. 15. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Delivering Continuously • “Always Be Deploying” • Every commit could end up in production today • CI Flow • Check in • Build Code • Run Unit Tests • Run UI/JavaScript Tests (if any) • Run Integrations • Deploy to Dockerhub • Push Docker Image to Target Cloud Environment 15
  16. 16. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ More CI • Docker Images + Cloud CI tool: • Spin up backing services in containers • Run integration tests against isolated backing services • Higher degree of confidence in builds • Tested artifact is the deployed artifact, with no changes. • Backing services can be 3rd party products or your own services • Acceptance Test environments spun up on demand • Choose which services are real and which are simulators • “Battlefield simulator” 16
  17. 17. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ From Commit to Cloud 17 DEMO
  18. 18. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Introducing SteelToe • http://steeltoe.io/ • Spring Cloud Clients in ASP.NET and ASP.NET Core • Spring Cloud Configuration Server • Service Discovery with Eureka • Spring Cloud Connectors • Works with OSS products or Pivotal Spring Cloud Services • Initial Release Q3 2016 • Open Source • https://github.com/SteelToeOSS 18
  19. 19. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ External Configuration • application.json file provides local defaults • config.AddEnvironmentVariables() adds raw environment vars to config • config.AddCloudFoundry() adds bound service metadata to config • Add Configuration Server client to get config from SCCS. • All configuration is last-added-wins - you choose override order 19
  20. 20. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Connectors • SQL Server + Entity Framework 6 (Windows) • mySQL • Redis • RabbitMQ* 20
  21. 21. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Data Services in Core • Database Clients • SQL Server • Postgres • MongoDB • RESTful DBs • Not available • DB2 • Oracle (yet) • Entity Framework 1.0 (not to be confused with EF6 ) 21
  22. 22. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Database Backing Services via External Configuration 22 DEMO
  23. 23. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Service Discovery with Eureka 23 http://grabs.services.mycompany.com/api/grabshttp://grabs/api/grabs • Create DiscoveryHttpClientHandler instance • Pass as parameter to HttpClient • Make a simple HTTP request • SteelToe takes care of URL changes • Application code is never aware of real location of backing service
  24. 24. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Service Discovery and Consumption 24 DEMO
  25. 25. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Summary and Take-aways • Small gap from empty project to working service • No more giant monolith framework • “Micro” is the default way of doing things • Build modern microservices in C# on any device (Mac, Linux, Windows) and deploy to modern PaaS targets. • .NET and Java apps can interoperate in the same microservices ecosystem. • We can stop using IIS. 25
  26. 26. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Learn More. Stay Connected. Pre-order our book, check out the github repo: http://github.com/microservices-aspnetcore Contribute to SteelToe! Related Session: Migrating .NET Apps to CF @springcentral spring.io/blog @pivotal pivotal.io/blog @pivotalcf http://engineering.pivotal.io

×