seninel部署
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

README.md 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Sentinel DataSource Eureka
  2. Sentinel DataSource Eureka provides integration with [Eureka](https://github.com/Netflix/eureka) so that Eureka
  3. can be the dynamic rule data source of Sentinel.
  4. To use Sentinel DataSource Eureka, you should add the following dependency:
  5. ```xml
  6. <dependency>
  7. <groupId>com.alibaba.csp</groupId>
  8. <artifactId>sentinel-datasource-eureka</artifactId>
  9. <version>x.y.z</version>
  10. </dependency>
  11. ```
  12. Then you can create an `EurekaDataSource` and register to rule managers.
  13. SDK usage:
  14. ```java
  15. EurekaDataSource<List<FlowRule>> eurekaDataSource = new EurekaDataSource("app-id", "instance-id",
  16. Arrays.asList("http://localhost:8761/eureka", "http://localhost:8762/eureka", "http://localhost:8763/eureka"),
  17. "rule-key", new Converter<String, List<FlowRule>>() {
  18. @Override
  19. public List<FlowRule> convert(String o) {
  20. return JSON.parseObject(o, new TypeReference<List<FlowRule>>() {
  21. });
  22. }
  23. });
  24. FlowRuleManager.register2Property(eurekaDataSource.getProperty());
  25. ```
  26. Example for Spring Cloud Application:
  27. ```java
  28. @Bean
  29. public EurekaDataSource<List<FlowRule>> eurekaDataSource(EurekaInstanceConfig eurekaInstanceConfig, EurekaClientConfig eurekaClientConfig) {
  30. List<String> serviceUrls = EndpointUtils.getServiceUrlsFromConfig(eurekaClientConfig,
  31. eurekaInstanceConfig.getMetadataMap().get("zone"), eurekaClientConfig.shouldPreferSameZoneEureka());
  32. EurekaDataSource<List<FlowRule>> eurekaDataSource = new EurekaDataSource(eurekaInstanceConfig.getAppname(),
  33. eurekaInstanceConfig.getInstanceId(), serviceUrls, "flowrules", new Converter<String, List<FlowRule>>() {
  34. @Override
  35. public List<FlowRule> convert(String o) {
  36. return JSON.parseObject(o, new TypeReference<List<FlowRule>>() {
  37. });
  38. }
  39. });
  40. FlowRuleManager.register2Property(eurekaDataSource.getProperty());
  41. return eurekaDataSource;
  42. }
  43. ```
  44. To refresh the rule dynamically,you need to call [Eureka-REST-operations](https://github.com/Netflix/eureka/wiki/Eureka-REST-operations)
  45. to update instance metadata:
  46. ```
  47. PUT /eureka/apps/{appID}/{instanceID}/metadata?{ruleKey}={json of the rules}
  48. ```
  49. Note: don't forget to encode your json string in the url.