seninel部署
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Sentinel DataSource Redis
  2. Sentinel DataSource Redis provides integration with Redis. make Redis
  3. as dynamic rule data source of Sentinel. The data source uses push model (listener) with redis pub/sub feature.
  4. **NOTE**:
  5. we not support redis cluster as a pub/sub dataSource now.
  6. To use Sentinel DataSource Redis, you should add the following dependency:
  7. ```xml
  8. <dependency>
  9. <groupId>com.alibaba.csp</groupId>
  10. <artifactId>sentinel-datasource-redis</artifactId>
  11. <version>x.y.z</version>
  12. </dependency>
  13. ```
  14. Then you can create an `RedisDataSource` and register to rule managers.
  15. For instance:
  16. ```java
  17. ReadableDataSource<String, List<FlowRule>> redisDataSource = new RedisDataSource<List<FlowRule>>(redisConnectionConfig, ruleKey, channel, flowConfigParser);
  18. FlowRuleManager.register2Property(redisDataSource.getProperty());
  19. ```
  20. _**redisConnectionConfig**_ : use `RedisConnectionConfig` class to build your connection config.
  21. _**ruleKey**_ : when the json rule data publish. it also should save to the key for init read.
  22. _**channel**_ : the channel to listen.
  23. you can also create multi data source listen for different rule type.
  24. you can see test cases for usage.
  25. ## Before start
  26. RedisDataSource init config by read from redis key `ruleKey`, value store the latest rule config data.
  27. so you should first config your redis ruleData in back end.
  28. since update redis rule data. it should simultaneously send data to `channel`.
  29. you may implement like this (using Redis transaction):
  30. ```
  31. MULTI
  32. PUBLISH channel value
  33. SET ruleKey value
  34. EXEC
  35. ```
  36. ## How to build RedisConnectionConfig
  37. ### Build with redis standLone mode
  38. ```java
  39. RedisConnectionConfig config = RedisConnectionConfig.builder()
  40. .withHost("localhost")
  41. .withPort(6379)
  42. .withPassword("pwd")
  43. .withDataBase(2)
  44. .build();
  45. ```
  46. ### Build with redis sentinel mode
  47. ```java
  48. RedisConnectionConfig config = RedisConnectionConfig.builder()
  49. .withRedisSentinel("redisSentinelServer1",5000)
  50. .withRedisSentinel("redisSentinelServer2",5001)
  51. .withRedisSentinelMasterId("redisSentinelMasterId").build();
  52. ```