Introduction to the

This article will explore the Soul gateway under the Nacos data synchronization example run, because the current feeling of this Nacos is not too friendly to beginners, and feel that there may be a bug, so separate write a detailed explanation of how to configure, for the next source code parsing, troubleshooting which lay the foundation for the problem

The sample run

This article is based on the latest version of the soul code released on January 23, 2019

Nacos and mysql Docker started

We use Docker to start a nacOS and mysql

docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:latest

#User name and password: nacos nacos
git clone https://github.com/nacos-group/nacos-docker.git 
cd .\nacos-docker\
docker-compose -f example/standalone-derby.yaml up
Copy the code

Access the NACOS interface: 127.0.0.1:8848, if it is normal, you can see the following five data configurations, congratulations, yours is working. If it’s empty, you have the same problem I do:

Problem Scenario Description

When we start admin, example-http, and Bootstrap, we may encounter one of the following problems:

  • 1. Both can be started normally, but the NACOS interface is empty. Bootstrap access fails and corresponding data cannot be found
  • 2. The bootstrap startup fails and the data is empty

Configure Nacos correctly

The Bootstrap configuration

First, make sure your Maven dependency has nacos-starter enabled, as shown below. If not, add it

        <! -- soul data sync start use nacos-->
        <dependency>
            <groupId>org.dromara</groupId>
            <artifactId>soul-spring-boot-starter-sync-data-nacos</artifactId>
            <version>${project.version}</version>
        </dependency>
Copy the code

Turn off all other synchronization methods except Nacos, and modify Nacos synchronization configuration to remove acM-related things, which are commented out! We used a new namespace soul to make it easy to view data

soul:
    file:
      enabled: true
    corss:
      enabled: true
    dubbo :
      parameter: multi
    sync:
#        websocket :
#             urls: ws://localhost:9095/websocket
#        zookeeper:
#             url: localhost:2181
#             sessionTimeout: 5000
#             connectionTimeout: 2000
#        http:
#             url : http://localhost:9095
        nacos:
              url: localhost:8848
              namespace: soul
#              acm:
#                enabled: false
#                endpoint: acm.aliyun.com
#                namespace:
#                accessKey:
#                secretKey:
Copy the code

If the data read is Null, the configuration is successful

The Admin configuration

First make sure nacos-client dependencies are introduced, if not, add them:

        <dependency>
            <groupId>com.alibaba.nacos</groupId>
            <artifactId>nacos-client</artifactId>
            <version>${nacos-client.version}</version>
        </dependency>
Copy the code

Config file, all other synchronization methods are closed, leaving only Nacos, and change the namespace to soul, comment out acm related (PS: when debugging, it seems that Websocket is also enabled, which is a little weird, but I didn’t look closely).

soul:
  database:
    dialect: mysql
    init_script: "META-INF/schema.sql"
    init_enable: true
  sync:
#    websocket:
#      enabled: false
#      zookeeper:
#          url: localhost:2181
#          sessionTimeout: 5000
#          connectionTimeout: 2000
#      http:
#        enabled: true
      nacos:
        url: localhost:8848
        namespace: soul
#        acm:
#          enabled: false
#          endpoint: acm.aliyun.com
#          namespace:
#          accessKey:
#          secretKey:
Copy the code

Try starting Admin and example-http to see if there is any error. If not, continue below

Nacos configuration

The Nacos management page is displayed. The user name and password are Nacos Nacos

Create a namespace for soul by selecting New Namespace from the menu bar on the left

At this point, restart the Admin and HTTP examples. In the Configuration Management – Configuration list, there are namespace names public and soul at the top. Click on Soul and, unsurprisingly, nothing

Manual Data Synchronization

From the previous article, we learned that there are five types of data: plug-in data, selector data, rules data, metadata, and authentication management data

Next, we enter the Admin background management interface, enter metadata, authentication management interface and plug-in management respectively, click Synchronize data, then click query on the NACOS configuration list page, and find that the data related to Auth, meta and Plugin appear

If this time to restart the HTTP example, may also appear the selector and the rule of the data (if not, then manually synchronize the data below), but we are trying to access interface: http://127.0.0.1:9195/http/order/findById? If id=1111, the rule cannot be found

At this point, we need to click on the corresponding rule and make changes (such as changing the state, whether the log is printed or not), then it will be synchronized to nacOS, and the interface will return normally again

In this way, the basic can run, but the problem is still very big, the biggest problem is that there is no automatic synchronization of the full data, need to manually synchronization

conclusion

This article documents an imperfect solution to an unsuccessful Nacos run, which requires further source code exploration to see the problem

Refer to the link

  • KaitoShy: Introduction to the Soul Gateway (7) : Data synchronization mode – NACOS configuration

Soul Gateway source code analysis article list

Github

  • Soul source reading (a) overview

  • Soul source code reading (two) the initial run of the code

  • HTTP request processing overview

  • Dubbo Request Overview

  • Soul Gateway source code reading (five) request type exploration

  • Soul Gateway source code reading (6) Sofa request processing overview

  • Soul gateway source code reading (seven) a stream limit plug-in exploration

  • Soul gateway source code reading (eight) route matching exploration

  • Soul Gateway source code reading (nine) plug-in configuration load preliminary discussion

  • Soul Gateway source code reading (ten) custom simple plug-in written

  • Soul Gateway source code read (11) request processing summary

  • Soul Gateway source code reading (12) data synchronization preliminary -Bootstrap end

  • Soul Gateway source code reading (thirteen) Websocket synchronization data -Bootstrap end

  • Soul Gateway source code reading (14) HTTP data synchronization -Bootstrap end

  • Zookeeper data synchronization -Bootstrap end

  • Soul Gateway source code reading (16) Nacos data synchronization example run

  • HTTP parameter request error

The Denver nuggets

  • Soul Gateway source code read (a) overview

  • Soul Gateway source code reading (two) the initial operation of the code

  • Soul Gateway source code reading (3) Request processing overview

  • Dubbo Request Overview

  • Soul Gateway source code reading (five) request type exploration

  • Soul Gateway source code reading (6) Sofa request processing overview

  • Soul gateway source code reading (seven) a stream limit plug-in exploration

  • Soul gateway source code reading (eight) route matching exploration

  • Soul Gateway source code reading (nine) plug-in configuration load preliminary discussion

  • Soul Gateway source code reading (ten) custom simple plug-in written

  • Soul Gateway source code read (11) request processing summary

  • Soul Gateway source code reading (12) data synchronization

  • Soul Gateway source code reading (thirteen) Websocket synchronization data -Bootstrap end

  • Soul Gateway source code reading (14) HTTP data synchronization -Bootstrap end

  • Zookeeper data synchronization -Bootstrap end

  • HTTP parameter request error