Hello Weijie,

Annotation to use it without Spring, maybe we can do that:

```
@ElasticScheduled(
        cron = "0/5 * * * * ?",
        jobName = "SimpleTestJob",
        shardingTotalCount = 3,
        shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou",
        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 final class JavaMain {
    .....
    public static void main(final String[] args) throws IOException {
        CoordinatorRegistryCenter regCenter = setUpRegistryCenter();
        TracingConfiguration<DataSource> tracingConfig = new
TracingConfiguration<>("RDB", setUpEventTraceDataSource());

ScheduleAnnotationJobBootstrap.newBuilder(SimpleTestJob.class).setRegCenter(regCenter).addExtraConfigurations(tracingConfig).build().schedule();
    }
    .....
}

```


------------------
Sincerely,
SunKai  Cai (skai)

吴伟杰 <wuwei...@apache.org> 于2021年8月12日周四 上午11:07写道:

> Hi sunkai,
>
> If we define the annotations in API module, we also need to define how
> to use it without Spring.
>
> ------------------
>
> Sincerely,
> Weijie Wu (TeslaCN)
> Apache ShardingSphere
>
> sk c <sunkai....@gmail.com> 于2021年8月11日周三 下午7:53写道:
> >
> > Hello Weijie,
> >
> > Thank you,  good ideas.  Maybe we can do that:
> >
> >
> > 1.  Move the `@ElasticScheduled` annotation to `api/annotation`.  We can
> > have the same annotation , and different annotation processor without
> > Spring.
> >
> > 2.  Yes, this is important. I have a idea like that:
> >
> > Set Scheduled
> > ```
> > package
> >
> org.apache.shardingsphere.elasticjob.lite.spring.core.annotation.job.impl;
> > @ElasticScheduled(
> >         cron = "0/5 * * * * ?",
> >         jobName = SimpleTestJobFirst
> >         shardingTotalCount = 3,
> >         shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou",
> >         extraConfigurations = {"SimpleTracingConfiguration"}
> > )
> > public class SimpleTestJob implements CustomJob {
> >
> >     @Override
> >     public void execute(final ShardingContext shardingContext) {
> >     }
> >
> > }
> > ```
> >
> > Set Configurable
> >
> > ```
> > //spring example
> > @Configurable
> > @EnableElastic(scanBasePackages =
> >
> "org.apache.shardingsphere.elasticjob.lite.spring.core.annotation.job.impl")
> > public class ElasticConfig {
> >
> >     @Bean
> >     public DataSource dataSource() {
> >         BasicDataSource dataSource = new BasicDataSource();
> >         dataSource.setDriverClassName("org.h2.Driver");
> >         dataSource.setUrl("jdbc:h2:mem:job_event_storage");
> >         dataSource.setUsername("sa");
> >         dataSource.setPassword("");
> >     }
> >
> >     @Bean("SimpleTracingConfiguration")
> >     public TracingConfiguration<DataSource> myTracingConfiguration() {
> >         return new TracingConfiguration<>("RDB", dataSource());
> >     }
> > }
> > ```
> > or
> >
> > ```
> > //spring boot example
> > @Configurable
> > @EnableElastic(scanBasePackages =
> >
> "org.apache.shardingsphere.elasticjob.lite.spring.core.annotation.job.impl")
> > public class ElasticConfig {
> >
> >     @ConditionalOnBean(DataSource.class)
> >     @Bean("SimpleTracingConfiguration")
> >     public TracingConfiguration<DataSource> myTracingConfiguration(final
> > DataSource dataSource) {
> >         return new TracingConfiguration<>("RDB", dataSource);
> >     }
> > }
> > ```
> >
> > 3.  Of course
> >
> > ------------------
> > Sincerely,
> > SunKai  Cai (skai)
> >
> > 吴伟杰 <wuwei...@apache.org> 于2021年8月11日周三 下午6:38写道:
> >
> > > Hi Sunkai,
> > >
> > > I have some ideas about your proposal:
> > > 1. Could we consider using the annotation without Spring?
> > > 2. Could we configure the jobs by annotations only? How to configure
> > > the JobExtraConfiguration like TracingConfiguration by annotations?
> > > 3. Support using YAML to configure jobs without Spring. This can refer
> > > to how ShardingSphere does.
> > >
> > > ------------------
> > >
> > > Sincerely,
> > > Weijie Wu (TeslaCN)
> > > Apache ShardingSphere
> > >
> > > sk c <sunkai....@gmail.com> 于2021年8月10日周二 下午3:43写道:
> > > >
> > > > Hi everyone,
> > > >
> > > > I prefer to discuss the annotation of ElasticJob  plan.
> > > >
> > > > example:
> > > >
> > > > ```
> > > > @ElasticScheduled(
> > > >         cron = "0/5 * * * * ?",
> > > >         jobName = "SimpleTestJobSecond",
> > > >         shardingTotalCount = 3,
> > > >         shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou",
> > > >         jobListenerTypes = {"NOOP", "LOG"},
> > > >         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) {
> > > >     }
> > > >
> > > > }
> > > > ```
> > > >
> > > > ```
> > > > @Configuration
> > > > @EnableElastic(scanBasePackages =
> > > > "org.apache.shardingsphere.elasticjob.lite.example.job.simple")
> > > > public class ElasticConfig {
> > > >
> > > > }
> > > > ```
> > > >
> > > > we can look at it on
> > > > https://github.com/apache/shardingsphere-elasticjob/pull/1954
> > > >
> > > > I am going to work it soon. Please remind me if you have a
> suggestion.
> > > >
> > > >
> > > > ------------------
> > > > Sincerely,
> > > > SunKai  Cai (skai)
> > >
>

Reply via email to