. . .

Dispatcher

Introduction

The Dispatcher service is an API Gateway providing a way to route APIs. It is built based on the Spring Cloud Gateway and includes all its features (as describe in the Spring Cloud Gateway public documentation). It also provides path rewriting rules for Yambas and the ApiOmat cloud environment. See How It works to have a deeper understanding of how the Spring Cloud Gateway works.

Installation

See [Dispatcher] Installation.

Use

Dispatcher loads all rulesets at service start. Therefore Consul is queried for all existing services and the contextPath of each service is used to build up a rule for redirection to that service if the context path matches. If new services are registered at Consul, the ruleset has to be refreshed for Dispatcher to become aware of new services. More information: Actuator API

Reloading rules

bash

bash
curl -X POST localhost:8000/actuator/gateway/refresh

Getting existing rules

bash

bash
curl localhost:8000/actuator/gateway/routes

Service registration tweaks

Other services can modify the behavior how they get registered at Dispatcher using tags in the discovery configuration ( spring.cloud.consul.dicovery.tags ):

  • registerAsYambasContextPath: If set, the microservice's REST interface path will be rewritten to match the YAMBAS REST path; this is especially used for generated microservices to make them transparent to existing SDKs.

  • notRegisterOnGateway: If set, the microservice will not be exposed through the gateway and will be only accessible behind the Dispatcher.

CORS handling

From version 1.0.1 Dispatcher have the following CORS configuration as default :

gateway:
	default-filters:
    - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
    globalcors:
		corsConfigurations:
			'[/**]':
				allowedOrigins: "*"
				allowedHeaders: "*"
				allowedMethods:
				- GET
				- POST
				- PUT
				- DELETE
				- OPTIONS

This mean that by default :

  • Dispatcher accept call any path, from any origin, with any headers using http method GET, POST, PUT, DELETE or OPTIONS.

  • Dispatcher use a global filter "DedupeResponseHeader" which will remove duplicate value for headers "Access-Control-Allow-Credentials" and "Access-Control-Allow-Origin" (As default it keep the first value only).

Further info

For a deeper use of the Spring Cloud Gateway features please refer to the following documentation links :