You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "Harif-Rahman (via GitHub)" <gi...@apache.org> on 2023/04/11 07:44:51 UTC

[GitHub] [shardingsphere] Harif-Rahman opened a new issue, #25102: Custom sharding algorithm with dependency bean in 5.x version.

Harif-Rahman opened a new issue, #25102:
URL: https://github.com/apache/shardingsphere/issues/25102

   ## Question
   
   **For English only**, other languages will not accept.
   We are planning to upgrade shardingsphere from 4.0.1 to 5.x
   
   We already have customshardingalgorithm to get the shard id from on datastore like redis.
   
   4.0.1 code : 
   shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new ComplexShardingStrategyConfiguration(CLIENT_ID, appShardingAlgorithm));
   
   
   @Component
   public class AppShardingAlgorithm implements ComplexKeysShardingAlgorithm<Long> {
     private final ShardService shardService;
   
     @Autowired
     public AppShardingAlgorithm(
         ShardService shardService
     ) {
       this.shardService = shardService;
     }
   
     @Override
     @SuppressWarnings("unchecked")
     public Collection<String> doSharding(Collection<String> availableTargetNames, ComplexKeysShardingValue<Long> shardingValues) {
       // get shard id from redis
       return applicableTargetNames;
     }
   }
   
   In the version 5.x i can't able to pass the custom object like i used earlier whatever the doc i referred its expecting me to pass it as class_based like the below : 
   
   [ shardingRuleConfig.setDefaultDatabaseShardingStrategy(new ComplexShardingStrategyConfiguration(CLIENT_ID, "appShardingAlgorithm"));
       Properties propsComplex = new Properties();
       propsComplex.setProperty("strategy", "COMPLEX");
       propsComplex.setProperty("algorithmClassName",
           "a.b.c.AppShardingAlgorithm");
       shardingRuleConfig.getShardingAlgorithms().put("appShardingAlgorithm", new AlgorithmConfiguration("CLASS_BASED", propsComplex));](url)
   
   In AppShardingAlgorithm class i have dependency to get the shard details from db or redis in this case i need to have that dependency for this.
   In this case how to pass the custom object for the sharding algorithm ?
   
   Before asking a question, make sure you have:
   
   - Googled your question.
   - Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more details. 
   If no response anymore and we cannot reproduce it on current information, we will **close it**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] Harif-Rahman closed issue #25102: Custom sharding algorithm with dependency bean in 5.x version.

Posted by "Harif-Rahman (via GitHub)" <gi...@apache.org>.
Harif-Rahman closed issue #25102: Custom sharding algorithm with dependency bean in 5.x version.
URL: https://github.com/apache/shardingsphere/issues/25102


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] Harif-Rahman commented on issue #25102: Custom sharding algorithm with dependency bean in 5.x version.

Posted by "Harif-Rahman (via GitHub)" <gi...@apache.org>.
Harif-Rahman commented on issue #25102:
URL: https://github.com/apache/shardingsphere/issues/25102#issuecomment-1514138067

   Thanks 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] Pace2Car commented on issue #25102: Custom sharding algorithm with dependency bean in 5.x version.

Posted by "Pace2Car (via GitHub)" <gi...@apache.org>.
Pace2Car commented on issue #25102:
URL: https://github.com/apache/shardingsphere/issues/25102#issuecomment-1503086583

   @Harif-Rahman In this case, you can try to obtain custom beans through the static methods provided by Spring ApplicationContext, or provide a utility class for `get shard id from redis`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org