. . .

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
curl -X POST localhost:8000/actuator/gateway/refresh

Getting existing rules

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 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 means that by default :

  • Dispatcher accepts calls from any path, from any origin, with any headers using the http methods GET, POST, PUT, DELETE or OPTIONS.

  • Dispatcher uses a global filter DedupeResponseHeader which will remove duplicate values for the headers Access-Control-Allow-Credentials and Access-Control-Allow-Origin (By default it keeps the first value).

Further info

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