In this lab we will continue to add functionality to the Fortune Teller application. We will explore how to use the ASP.NET Core Configuration services and how to add the Config Server as a source of configuration data using the Steeltoe Config Server provider.
After completing Lab05, the app state should be as follows:
- The
Fortune Teller Service
uses a in-memory database to hold Fortunes. - The
Fortune Teller Service
serves up random fortunes from the database. - The
Fortune Teller UI
uses aFortuneServiceClient
and is able to communicate with theFortune Teller Service
.
The goals for Lab 6 are:
- Use Config Server to centralize configuration for both applications.
For background information, see: ASP.NET Core Configuration documentation and ASP.NET Core Environment documentation.
In this exercise we will startup a Config Server locally and move our configuration data to the locally running Config Server. We will also make the changes necessary to pull the configuration data from the Config Server into our application. Specifically, we will use the Steeltoe Config Server client
to pull config data from the Config Server.
For background information, see: Cloud Config Server documentation.
Here we setup and run a Config Server locally, for easier development and testing.
-
Open a command window and change directory to Workshop/ConfigServer
> cd Workshop/ConfigServer
-
Startup the Config Server
> ./mvnw spring-boot:run
It will start up on port 8888 and serve configuration data from
Workshop/ConfigServer/steeltoe/config-repo
. You can verify the config server is running via the health check endpoint http://localhost:8888/admin/health
For each project, make changes to your .csproj
files to include the Steeltoe Config Server provider NuGet.
For each project, make changes to Program.cs
to add the Steeltoe Config Server provider to the ConfigurationBuilder
.
For each project, make changes to appsettings.json
to configure the Steeltoe Config Server client.
At a minimum, we need to tell the client what URL to use to make requests of the Config Server and what configuration data to request.
Use spring:application:name
to configure the name of the application for each project. Use the following names:
- Fortune_Teller_Service - use
fortuneService
- Fortune_Teller_UI - use
fortuneui
In this step we move some of the configuration data from both of the appsettings
files to files in the Workshop/ConfigServer/steeltoe/config-repo. This is the directory the Config Server that we started above uses to serve configuration data.
You will want to establish four files in the Workshop/ConfigServer/steeltoe/config-repo directory. At this point some of these files may be empty, but in future labs we will be adding additional configuration data.
- application-Development.yml
- application.yml
- fortuneService.yml
- fortuneui.yml
Go through your appsettings.json
and appsettings.Development.json
files and move configuration data into the most appropriate files above. For example, the common logging configuration for both FortuneUI and Fortune Service could combined and moved into application.yml and application-Development.yml. Configuration information that is specific for FortuneUI, could be added to fortuneui.yml.
When you're done, the only thing left in appsettings.json
should be configuration data needed by the Config Server client.
Run both Fortune-Teller applications to verify they run as they did before centralizing the configuration. Run the applications in either a command window or VS2017.
To create an instance of the Config Server service in your org/space and populate it with configuration data, follow these instructions:
-
Create your own GitHub repo to hold your Config Server data.
-
Open a command window and change directory to your starting lab point.
> cd Workshop/Start
-
In Visual Studio, open the
config-server.json
file in the solution folder. -
Modify its contents to point to the GitHub repo you just created above.
-
Using the command window, create an instance of the config server on Cloud Foundry. When we create it, we will set its configuration using the config-server.json file we modified above:
> cf create-service p-config-server standard myConfigServer -c config-server.json
-
Add the contents of Workshop/ConfigServer/steeltoe/config-repo to the GitHub repo you just created.
-
Wait for the service to become available on Cloud Foundry before proceeding to the next step.
> cf services
You need to configure your applications to bind to the Config Server service instance you created above.
Open the manifest.yml
files for both projects and add a services
section and include the Config Server instance you created above.
In some cases you may find that your Cloud Foundry setup has been installed using self-signed certificates. If that is the case, you will likely run into certificate verification errors when communicating with the Config Server. If that is the case you can disable certificate validation by adding
spring:cloud:config:validate_certificates=false
to your configuration file.
Check with your instructor to see if you need to do this. If you do, you will need to do this for each project.
Publish, push and verify the applications run on Cloud Foundry. Make any adjustments to the configuration in GitHub to get the applications to work properly.
-
Open and Login to Pivotal AppsManager in a browser.
-
Select your Org and Space and view the two Fortune Teller applications.
- Select the services tab and select Config Server instance.
- Select the Manage link to view the detail configuration of the Config Server.
Continue the workshop with Lab 7 - Service Discovery - Eureka Server