You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/09/01 18:32:40 UTC

[GitHub] [shardingsphere-elasticjob] sunkai-cai commented on issue #1445: Support Annotation Job

sunkai-cai commented on issue #1445:
URL: https://github.com/apache/shardingsphere-elasticjob/issues/1445#issuecomment-910552133


   I prefer to discuss the annotation of ElasticJob plan.
   
   1. define annotation `ElasticJobConfiguration` in `api` , using  like this:
   
   ```
   @ElasticJobConfiguration(
           cron = "0/5 * * * * ?",
           jobName = "SimpleTestJobFirst",
           shardingTotalCount = 3,
           shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou",
           jobListenerTypes = {"NOOP", "LOG"},
           extraConfigurations = {SimpleTracingConfigurationFactory.class},
           props = {
                   @ElasticJobProp(key = "print.title", value = "test title"),
                   @ElasticJobProp(key = "print.content", value = "test content")
           }
   )
   public class SimpleTestJob implements CustomJob {
       
       @Override
       public void execute(final ShardingContext shardingContext) {
       }
       
   }
   ```
   
   ```
   public class SimpleTracingConfigurationFactory implements JobExtraConfigurationFactory {
      
       public JobExtraConfiguration getJobExtraConfiguration() {
           BasicDataSource dataSource = new BasicDataSource();
           dataSource.setDriverClassName(org.h2.Driver.class.getName());
           dataSource.setUrl("jdbc:h2:mem:job_event_storage");
           dataSource.setUsername("sa");
           dataSource.setPassword("");
           return new TracingConfiguration<>("RDB", dataSource);
       }
   }
   ```
   
   ```
   //Java example
   public final class JavaMain {
       .....
       public static void main(final String[] args) throws IOException {
           CoordinatorRegistryCenter regCenter = setUpRegistryCenter();
           (new ScheduleJobBootstrap(regCenter,new SimpleTestJob())).schedule();
       }
       .....
   }
   ```
   
   2. define annotation `EnableElastic` in spring-code , using like this:
   
   ```
   //spring example
   @Configurable
   @EnableElastic(scanBasePackages = "org.apache.shardingsphere.elasticjob.lite.spring.core.annotation.job.impl")
   public class ElasticConfig {
   
   }
   ```
   or
   
   ```
   //spring boot example
   @Configurable
   @EnableElastic(scanBasePackages = "org.apache.shardingsphere.elasticjob.lite.spring.core.annotation.job.impl")
   public class ElasticConfig {
       
   }
   ```


-- 
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