Using Steeltoe to build resilient .NET Core Microservices with Pivotal Cloud Foundry
By Senan Almosawie
This blog provides a high-level overview of Steeltoe, and discusses reference application that utilizes Steeltoe to build resilient Cloud native .NET applications, and deployment to Pivotal Cloud Foundry.
Why should you use Steeltoe?
Steeltoe makes developing microservices for .NET platform painless. For all their benefits, microservice architectures expose many distributed computing problems that traditional monoliths avoided. Steeltoe brings the power of resilient, scalable microservices to .NET developers, without all the headache.
Steeltoe Features:
- Highly Available Service Discovery
- Highly Available Config Server
- Circuit Breaker
- Cloud Database Connectors (i.e MySQL, Postgres, Redis, RabbitMQ, OAuth2, and MS SQL Server)
- Cloud Security Providers: (i.e. OAuth2 SSO Provider, JWT resource protection, and Redis-backed Key Ring Repository)
- Blue/Green deployment support
Steeltoe Music Store Example
Steeltoe Music Store Application Supports the following:
- Spring Cloud Config Server Client for centralized application configuration
- Netflix Eureka Server Client for service discovery
- Steeltoe Connector for connecting to MySql using EFCore
- Steeltoe CircuitBreaker to help prevent cascading failures from lower level service failures
- Steeltoe Management for enabling management actuator endpoints that can be used by the Pivotal Apps Manager
- Optionally uses Steeltoe Redis Connector to connect to a Redis cache for Session storage. Note: This is required if you want to scale the MusicStoreUI component to multiple instances.
- Optionally uses Steeltoe Redis DataProtection provider to allow the DataProtection KeyRing to be stored in a Redis cache. Note: This is also required if you want to scale the MusicStoreUI component to multiple instances.
- Optionally uses Netflix Hystrix Dashboard for monitoring Circuit Breakers
Architecture Diagram
Services Overview
- Music Store UI — provides the UI to the MusicStore application and all of its services.
- Music Store Service — provides a RESTful API to the MusicStore and its backend Music database.
- Order Processing Service — provides a RESTful API for the Order processing service and its backend Order database.
- Shopping CartS ervice — provides a RESTful API to the ShoppingCart service and its backend ShoppingCart database.
Sample Appsettings.json
As you can see from the snippet, appsettings.json
references localhost for Config Server and Eureka. However, as soon as the app is bound to Config Server settings (provided using environment variables), the local settings will be overridden.
Sample manifest.yml:
As you can see from the snippet above, manifest.yml
, when cf push
command is executed, the command will automatically locate the manifest and deploy the application to Pivotal Cloud Foundry.
Getting Started
Clone the application repo. (i.e. git clone)
CloudFoundry Pre-requisites
- Install Pivotal Cloud Foundry
- Install Spring Cloud Services
- Install .NET Core SDK.
- Install Microsoft Visual Studio to customize files. (Optional)
- Install Redis service if you want to use Redis for Session storage and KeyRing storage.
- Install Pivotal Apps Manager 1.11+ if you want to access Management endpoints from the Apps Manager.
Setup Services on CloudFoundry
As mentioned above, the application is dependent on the following services:
- Spring Cloud Config Server
- Netflix Eureka Server
- MySql Database Server
- Redis Cache — Optional! Note: you have to specifically build/publish MusicStoreUI service to use Redis (see details below).
Note: Redis Cache is required if you want to scale the MusicStoreUI app to multiple instances (e.g. cf scale musicui-sa -i 2+). Redis is not required to scale other microservices.
cf target -o myOrg -s mySpace
cd MusicStore
SET USE_REDIS_CACHE=true
orexport USE_REDIS_CACHE=true
(Optional)start createCloudFoundryServices.cmd
or./createCloudFoundryServices.sh
This will create all of the services needed by the application. Specifically, it creates:
- mStoreConfig — Spring Cloud Config Server instance
- mStoreRegistry — Spring Cloud Eureka Server instance
- mStoreAccountsDB — MySql database instance for Users and Roles (Identity)
- mStoreOrdersDB — MySql database instance for Orders
- mStoreCartDB — MySql database instance for ShoppingCarts
- mStoreStoreDB — MySql database instance for MusicStore
- mStoreRedis(optionally) — Redis cache instance used by MusicStoreUI for storing Session state
Building & Pushing App — CloudFoundry
Once the services have been created and ready on CloudFoundry (i.e. check via cf services
) then you can push the 4 applications:
pushShoppingCartService.cmd win10-x64 netcoreapp2.0
or./pushShoppingCartService.sh ubuntu.14.04-x64 netcoreapp2.0
pushOrderService.cmd win10-x64 netcoreapp2.0
or./pushOrderCartService.sh ubuntu.14.04-x64 netcoreapp2.0
pushMusicStoreService.cmd win10-x64 netcoreapp2.0
or./pushMusicStoreService.sh ubuntu.14.04-x64 netcoreapp2.0
pushMusicStoreUI.cmd win10-x64 netcoreapp2.0
or./pushMusicStoreUI.sh ubuntu.14.04-x64 netcoreapp2.0
Once you have pushed all the applications to Cloud Foundry, if you do a cf a
, you should see the following applications:
- musicui-sa — Music store User Interface
- musicstore-sa — Music store database micro-service
- orderprocessing-sa — Order processing micro-service
- shoppingcart -sa — Shopping cart micro-service
Another way to confirm is by logging into Pivotal Web Services and checking the existence of each service, etc.
Senan Almosawie is an Enterprise Architect at TribalScale with over 18 years of solid work experience in designing and architecting enterprise software solutions. Senan has previous experience in areas, including Point of Sale, Telecommunications, Health Care Systems, Financial applications, Microservice architecture and development on Cloud Foundry, Google Cloud, AWS, and more. He has strong Agile transformation expertise for Fortune 100 clients. He has a strong passion for architecture and performance oriented design. He’s a full stack technology expert who is always looking to connect with like-minded individuals.
Join our fast growing team and connect with us on Twitter, LinkedIn & Facebook! Learn more about us on our website.