Skip to content

Service Discovery

Angular usage

When you create a new client service, and that service make http calls using HttpClient, all the request are filtered by the discovery interceptor.

Discovery process

Compared with the .NET method, angular SPAs don't communicates with the registry provider directly. Instead it uses the server as intermediate to recover all the services registered.

The angular service discovery flow includes 3 important steps to prepare the application:

discovery service process

  1. Bootstrap configuration: the bootstrap module needs to load the file which contains the address of its own backend.

    This service address will be used to get the application configuration.

  2. Application configuration: Once the bootstrap module had been initialized, the configuration module request to the server the entire SPA configuration bundle.

    The discovery module (backend) provides a configuration contributor which expose all the services that are in the service registry, those services are included into the configuration bundle and returned to the client.

  3. Discovery interceptor: Now that all the services description are loaded the discovery module controls all the request using an interceptor.

    This interceptor replace the host of the request if it match with any service registered using one of the available addresses.

Bootstrap configuration

The configuration file for the bootstrap module has the objective to store the BFF address in order to access to all the features, for instance: application configuration, localization, service discovery registry, and others ...

Tip

This file is part of the assets folder, which is copied over to the build directory by Angular CLI during the build process of your app. That allow us to change the configuration set after the application had been built by hand, using a script or many other ways.

By default the bootstrap module will get this file from assets/bootstrap/configuration.json, but you can change it using the environment files. For instance:

environment.ts for "development"

TypeScript
1
2
3
4
export const environment = {
    production: false,
    bootstrapConfigurationFileUri: '/assets/bootstrap/configuration.dev.json'
};

environment.prod.ts for "development"

TypeScript
1
2
3
4
export const environment = {
    production: true,
    bootstrapConfigurationFileUri: '/assets/bootstrap/configuration.json'
};

And then in your application module:

TypeScript
1
2
3
    SuiteBootstrapDomainModule.forRoot(
        environment.bootstrapConfigurationFileUri
    ),

Avoiding the discovery service interceptor

In case you are trying to make a request to any server without using the discovery service, you can create a new instance of HttpClient without interceptors using HttpBackend.

TypeScript
1
2
3
4
5
    private httpClient: HttpClient;

    constructor(httpBackend: HttpBackend) {
        this.httpClient = new HttpClient(httpBackend);
    }