seninel部署
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

README.md 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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", flowRuleParser);
  18. FlowRuleManager.register2Property(eurekaDataSource.getProperty());
  19. ```
  20. Example for Spring Cloud Application:
  21. ```java
  22. @Bean
  23. public EurekaDataSource<List<FlowRule>> eurekaDataSource(EurekaInstanceConfig eurekaInstanceConfig, EurekaClientConfig eurekaClientConfig) {
  24. List<String> serviceUrls = EndpointUtils.getServiceUrlsFromConfig(eurekaClientConfig,
  25. eurekaInstanceConfig.getMetadataMap().get("zone"), eurekaClientConfig.shouldPreferSameZoneEureka());
  26. EurekaDataSource<List<FlowRule>> eurekaDataSource = new EurekaDataSource(eurekaInstanceConfig.getAppname(),
  27. eurekaInstanceConfig.getInstanceId(), serviceUrls, "flowrules", new Converter<String, List<FlowRule>>() {
  28. @Override
  29. public List<FlowRule> convert(String o) {
  30. return JSON.parseObject(o, new TypeReference<List<FlowRule>>() {
  31. });
  32. }
  33. });
  34. FlowRuleManager.register2Property(eurekaDataSource.getProperty());
  35. return eurekaDataSource;
  36. }
  37. ```
  38. To refresh the rule dynamically, you need to call [Eureka-REST-operations](https://github.com/Netflix/eureka/wiki/Eureka-REST-operations)
  39. to update instance metadata:
  40. ```
  41. PUT /eureka/apps/{appID}/{instanceID}/metadata?{ruleKey}={json of the rules}
  42. ```
  43. Note: don't forget to encode your JSON string in the url.