(Thirty-four) spring cloud micro-architecture b2b2c e-commerce services - the services gateway zuul primary articles

Please add source e-commerce platform Penguin beg: 1038774626. Why do I need API Gateway

1, to simplify the complexity of client calls

The number of instances in the micro-services architecture model back-end services in general is dynamic, in terms of hard to find the client access address service instances dynamically changing information. Thus based on the micro-program services in order to simplify the front end of the call logic, which usually involves a gateway API Gateway As a lightweight, while API Gateway will also implementation-dependent authentication logic to simplify the complexity of the cross call between the inner and services.

2, cutting data and polymeric

Generally speaking a different client demand for the display data is inconsistent, such as mobile phones or the Web side and end or low-latency network environment or high-latency network environment.

Therefore, in order to optimize the client experience, API Gateway can be tailored to the versatility of the response data to suit the needs of different clients. But also can be a plurality of API call logic polymerization, thereby reducing the number of request from the client, the client user experience optimized

3, multi-channel support

Of course, we can also provide for different channels and client different API Gateway, for the use of this mode is called by another well-known way Backend for front-end, among Backend for front-end mode, we can target different client were to create their BFF.

4, micro-services transformation of legacy systems

Micro systems for service reform is usually due to a problem more or less the original system, such as technical debt, code quality, maintainability, scalability and so on. API Gateway mode also applies to this type of transformation of legacy systems, the progressive realization of the repair of problems in the original system through the transformation of micro-services, so as to enhance existing business to enhance the response force. By introducing an abstraction layer, to achieve gradually replace the old with the new implementation.

In Spring Cloud system, Spring Cloud Zuul is to provide load balancing, reverse proxy, a certification authority API gateway.

Spring Cloud Zuul

Spring Cloud Zuul routing is an integral part of the micro-service architecture, providing dynamic routing, monitoring, edge flexibility, security and other services. Zuul Netflix is ​​produced based on a JVM routing and server load balancer.

We adopted the following code to understand how it works Zuul

Simple to use

1, adding a dependency

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>

Introducing spring-cloud-starter-zuul package

2, the configuration file

spring.application.name=gateway-service-zuul
server.port=8888
 
#这里的配置表示,访问/it/** 直接重定向到http://www.ityouknow.com/**
zuul.routes.baidu.path=/it/**
zuul.routes.baidu.url=http://www.ityouknow.com/

3, start class

@SpringBootApplication
@EnableZuulProxy
public class GatewayServiceZuulApplication {
 
	public static void main(String[] args) {
		SpringApplication.run(GatewayServiceZuulApplication.class, args);
	}
}

Start classes are added @EnableZuulProxy, the gateway supports routing.

History of the most simple case zuul on the configuration finished.

Guess you like

Origin blog.csdn.net/wiyzq/article/details/90764274