当前位置:网站首页>[microservices sentinel] cluster link | microservices cluster environment construction

[microservices sentinel] cluster link | microservices cluster environment construction

2022-06-25 00:45:00 Bulst

Cluster link

" Cluster link " The resource just called is shown in ( Stand alone real time ), Cluster link ( Single machine call link ) Page real-time to pull the operation of the specified client resources .

It offers two display modes : A call link that displays resources in a tree structure , The other one does not distinguish between call links to show the operation of resources .

Be careful : Cluster monitoring is memory state information , It only shows the resources that have been invoked after startup .

By default, it is displayed in a tree view

 Insert picture description here

  • The list shows all interfaces under the service , Including passage QPS, Reject QPS, Number of threads , Average RT, Minutes pass , Minutes to refuse .
  • 172.20.10.3:8721 For the current service ip Address , The port serves sentinel The interactive port of the console , The local service will play a role occupied by this port HttpServer, The Server Will be with sentinel Console interaction , such as sentinel A current limiting rule has been added to the console , Will put the rule data push Here it is HttpServer receive ,HttpServer Then register the rules to Sentinel in .
  • You can add flow control to the current resource 、 Downgrade 、 hotspot 、 Authorization and other operations .

List view :
 Insert picture description here

We can see that under the action list , Flow control 、 Downgrade 、 hotspot 、 Authorization and other options .

Next , We will introduce the above functions in detail .

Test environment ( Micro service cluster )

Father pom file

        <spring-cloud.version>Hoxton.SR9</spring-cloud.version>
        <spring-boot.version>2.3.2.RELEASE</spring-boot.version>
        <spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>

Code structure list

 Insert picture description here

Producer multi node deployment

 Insert picture description here

producer

/** *  producer controller * * @author issa **/
@RefreshScope
@RequestMapping(value = "/producer")
@RestController
public class ProducerController {
    

    @GetMapping("/{id}")
    @SentinelResource("test")
    public String producerById(@PathVariable(value = "id") String id) {
    

        ProducerVO producerVO = new ProducerVO();
        producerVO.setId(id);
        producerVO.setPort(UUID.randomUUID().toString());

        return producerVO.toString();
    }
}

Producer startup class

/** *  producer  * * @author issa **/
@EnableDiscoveryClient
@SpringBootApplication
public class ProducerApplication {
    

    public static void main(String[] args) {
    
        SpringApplication.run(ProducerApplication.class, args);
    }

}

consumer

/** *  consumer controller * * @author issavior **/
@RequestMapping(value = "/consumer")
@RestController
@RefreshScope
public class ConsumerController {
    

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProducerFeign producerFeign;

    @GetMapping("/rest/{id}")
    @SentinelResource("rest")
    public String restConsumerById(@PathVariable(value = "id") String id) {
    

        return restTemplate.getForObject("http://ossa-service-producer/producer/" + id, String.class);
    }

    @GetMapping("/feign/{id}")
    @SentinelResource("feign")
    public String feignConsumerById(@PathVariable(value = "id") String id) {
    

        return producerFeign.producerById(id);
    }
}

Consumer startup class

/** *  consumer  * * @author issavior */
@EnableFeignClients("com.ossa.common.feignapi")
@EnableDiscoveryClient
@SpringBootApplication
public class ConsumerApplication {
    
    public static void main(String[] args) {
    
        SpringApplication.run(ConsumerApplication.class, args);
    }

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
    

        return new RestTemplate();
    }
}

feignapi

/** * @author issavior */
@FeignClient(value = "ossa-service-producer")
@RequestMapping(value = "/producer")
public interface ProducerFeign {
    

    /** *  according to ID Query products  * * @param id  The primary key of the item ID * @return  Information about related products  */
    @GetMapping("/{id}")
    String producerById(@PathVariable(value = "id") String id);
}
原网站

版权声明
本文为[Bulst]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242001480246.html