This paper introduces the use of SpringCloud plug-in in Soul gateway framework, and analyzes part of the source code of SpringCloud plug-in module.

background

The Soul gateway framework has rich built-in plug-in support, where the SpringCloud plug-in is used to convert HTTP requests from clients into SpringCloud requests.

Use of the SpringCloud plug-in

  • Start the nacos (Nacos, version 1.2.0, is used as the registry for SpringCloud);
sh startup.sh -m standalone
Copy the code
  • Start the soul-admin application and enable support for the SpringCloud plug-in in the admin background;

  • The soul-bootstrap gateway application is added to rely on SpringCloud, and the nacos registry is configured to start the application.

    <dependency> <groupId>org.dromara</groupId> <artifactId>soul-spring-boot-starter-plugin-springcloud</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> < artifactId > spring - cloud - Commons < / artifactId > < version > 2.2.0. RELEASE < / version > < / dependency > < the dependency > <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-ribbon</artifactId> < version > 2.2.0. RELEASE < / version > < / dependency > < the dependency > < groupId > com. Alibaba. Cloud < / groupId > < artifactId > spring - the cloud - starter - alibaba - nacos - discovery < / artifactId > < version > 2.1.0. RELEASE < / version > < / dependency >Copy the code
    Cloud: nacos: Discovery: server-addr: 127.0.0.1:8848Copy the code
  • Log on to http://localhost:8848/nacos/#/login see if soul – the bootstrap to register nacos;

  • Configure the NACOS registry address and NACOS client dependencies in soul-example-SpringCloud, and then start the application. Check the gateway management background and see the list of registered back-end services.

  • Testing HTTP requests that can be forwarded to the backend SpringCloud service;

The problem summary

  1. soul-bootstrapBoot failure
ERROR 45890 --- [ main] c.a.c.n.registry.NacosServiceRegistry : nacos registry, soul-bootstrap register failed... NacosRegistration{nacosDiscoveryProperties=NacosDiscoveryProperties{serverAddr='', endpoint='', namespace='', WatchDelay =30000, logName= ", service='soul-bootstrap', weight=1.0, clusterName='DEFAULT', namingLoadCacheAtStart='false', metadata={preserved.register.source=SPRING_CLOUD}, registerEnabled=true, IP ='192.168.1.5', networkInterface= ", port=9195, Secure =false, accessKey= ", secretKey= "}}, java.lang.IllegalArgumentException: no server available at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:438) ~ [nacos - the client - 1.1.1. Jar: na] at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI (NamingProxy. Java: 386) ~ [nacos - the client - 1.1.1. Jar: na] at com.alibaba.nacos.client.naming.net.NamingProxy.registerService (NamingProxy. Java: 188) ~ [nacos - the client - 1.1.1. Jar: na]Copy the code
  • To solve:soul-bootstrapTo configure the NACOS registry address;

series

  • Soul source learning [1] – preliminary exploration
  • Soul source learning [2] – divide load balancing plug-in
  • Soul source learning [3] – Dubbo plug-in
  • Soul source learning [4] – RateLimiter stream limiting plug-in