“This is the 10th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

Nacos old history

Around November 2018, Spencer Gibb, co-founder of Spring Cloud, announced on the blog page of Spring's official website that Alibaba was open source Spring Cloud Alibaba and released the first preview version. This was later announced on Spring Cloud's official Twitter account.Copy the code

With this announcement, the outside world learned of Nacos’s birth. After all, it is the KPI product of the big factory. Let’s have a taste.

First, environmental preparation

  • Spring the Boot: 2.3.12

  • Spring Cloud: Hoxton.SR12

  • Spring Cloud Alibaba: 2.2.6. RELEASE

  • Maven: 3.5.4

  • Java 1.8 +

  • Oauth2 (Spring Security 5.3.9)

Install Nacos

Download Nacos at github.com/alibaba/nac…

Version: v1.2.1

Perform:

Linux/Unix/Mac: sh startup. Sh -m standalone Windows: CMD startup. CMD -m standaloneCopy the code

Startup is complete, visit: http://127.0.0.1:8848/nacos/, can enter the Nacos service management page, specific as follows:

Above, we can see the list of services that are started. At the same time, we can also configure the configuration of this service:

The configuration is as follows:

Here, we can set the configuration type, such as yaml, properties. The default is the latter, which we can set here:

Spring: Application: name: cas-server cloud: nacos: server-addr: 127.0.0.1:8848 Discovery: enabled: true Namespace: A48cec97-fa0f-48e0-97c7-0aced5c7ecbe # default public #group: mine #${nacos.runtime-env} heart-beat-interval: 10 heart-beat-timeout: 15 config: enabled: true #namespace: ${nacos.namespace} file-extension: Yaml # default properties #group: ${spring.application.name} shared-configs: -data-id: application-mysql.properties refresh: falseCopy the code

Services of different namespaces are interadjusted

In Nacos, there are several concepts, such as command space namespace, grouping group, and so on. Although the keywords are similar to K8s, the differences are significant. That’s what I want to talk about today. Here we have properties configured by default.

In Nacos, some concepts are introduced to divide different services into regions: Namespace, group let’s set up a namespace first.

So when we registered the service, we put the service in this onenew-NSStart the service. Let’s see the message:

We can see thatcas-serverThe namespace name of the service is new-ns.

Let’s go ahead and add a new service, put the new service under the default namespace, and assume that it is used to invoke the CAS-Server service.

Next, we invoke the service with a command:

curl -i -H "Accept: application/json" -H "Authorization:bearer fbbb08b5-fc9c-4bf9-a676-6a1d5d6a0dda" -X GET http://localhost:2001/api/user/get
Copy the code

You can see the log:

The log is the check_token interface that requests the unified authentication and Authentication Center. Since both services are registered with Nacos, they are requested directly by domain name.

But you can see from the log, throw an exception: Java. Lang. An IllegalStateException: No instances available for cas – server, this is because the corresponding IP cannot resolve the domain name. But from above, we can see clearly there is registration information, why can not access?

This is the first pothole Nacos now presents: the inability to access other services across namespaces. What if we put cas-Server under the default namespace as well?

Again, we invoke the service with a command and find that it can be requested normally:

We found that after a normal request, the information was returned, only 400 was returned, this is because my token is invalid, invalid token, please re-authenticate access.

Interadjust with services of different groups under the namespace

As mentioned above, services of different namespaces intertune with each other. Next, let’s look at how different groups of services of the same namespace intertune.

Similarly, we assume that cas-server is assigned to a new group:

Spring: Application: name: cas-server cloud: nacos: server-addr: 127.0.0.1:8848 Discovery: enabled: true group: mine heart-beat-interval: 10 heart-beat-timeout: 15Copy the code

The new rest-service is still in the default group DEFAULT_GROUP:

Next, we invoke the service with a command:

curl -i -H "Accept: application/json" -H "Authorization:bearer fbbb08b5-fc9c-4bf9-a676-6a1d5d6a0dda" -X GET http://localhost:2001/api/user/get
Copy the code

Let’s take a look at the log:

Found or like said earlier that request after, still throw an exception: Java. Lang. An IllegalStateException: No instances available for cas server. –

conclusion

Verification of these two cases in higher versions of Nacos also leads to the same conclusion: services of different groups under the same namespace cannot call each other, and services of the same group under different namespaces cannot call each other.

PS

I am not criticizing the Nacos team, but I hope the official release of the new feature as soon as possible.