Introduction to the

I recently started to re-engineer my company’s microservices at a new company, and chose NACOS in the registry. My previous company, Eureka, ran into some problems and wanted to try NacOS. The whole micro-service will also take Mica as the core of micro-service, interested friends can check the code cloud link: gitee.com/596392912/m… .

The problem

After nacOS and Spring Boot admin are integrated, it is found that only services before Admin is started can be monitored. Spring Boot Admin is a new service registration that relies on the HeartbeatEvent event.


We can see that both Eureka and Consul’s clients send this event.

Eureka



Consul

To solve the problem

Github Clone Spring-cloud-Alibaba found some changes in the local code, and the official has implemented this function.

However, the official version has not been released yet, so I consider copying the relevant code into my own project.

First copy NacosWatch


Note that there is an error here, you can write the following values or customize the properties configuration.

/** * watch delay,duration to pull new service from nacos server. */
private long watchDelay = 30000;
Copy the code

Then add the code for NacosWatch automation:

/** * NacosWatch automatically configures **@author L.cm
 */
@Configuration
public class NacosWatchAutoConfiguration {

	@Bean
	@ConditionalOnMissingBean
	@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.watch.enabled", matchIfMissing = true)
	public NacosWatch nacosWatch(NacosDiscoveryProperties nacosDiscoveryProperties) {
		return newNacosWatch(nacosDiscoveryProperties); }}Copy the code

Restart Spring Boot Admin, then start the other services in turn, and find that the new services are automatically synchronized to Spring Boot Admin.

Open source is recommended

Pay attention to our

Scan the above TWO-DIMENSIONAL code, more exciting content recommended every day!