Skip to content

Commit

Permalink
例子
Browse files Browse the repository at this point in the history
  • Loading branch information
qq254963746 committed Apr 22, 2016
1 parent bd8eb38 commit e383285
Show file tree
Hide file tree
Showing 58 changed files with 820 additions and 60 deletions.
2 changes: 1 addition & 1 deletion lts-example-jobclient/lts-example-jobclient-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobclient</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.7.1</version>
<version>1.6.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.github.ltsopensource.core.commons.utils.DateUtils;
import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.jobclient.JobClient;
import com.github.ltsopensource.jobclient.RetryJobClient;
import com.github.ltsopensource.jobclient.JobClientBuilder;
import com.github.ltsopensource.jobclient.domain.Response;

import java.util.Date;
Expand All @@ -15,13 +15,20 @@ public class Main {

public static void main(String[] args) {

JobClient jobClient = new RetryJobClient();
jobClient.setNodeGroup("test_jobClient");
jobClient.setClusterName("test_cluster");
jobClient.setRegistryAddress("zookeeper://127.0.0.1:2181");
jobClient.setJobCompletedHandler(new JobCompletedHandlerImpl());
jobClient.addConfig("job.fail.store", "mapdb");
jobClient.start();
// 方式1
// JobClient jobClient = new RetryJobClient();
// jobClient.setNodeGroup("test_jobClient");
// jobClient.setClusterName("test_cluster");
// jobClient.setRegistryAddress("zookeeper://127.0.0.1:2181");
// jobClient.setJobCompletedHandler(new JobCompletedHandlerImpl());
// jobClient.addConfig("job.fail.store", "mapdb");
// jobClient.start();

// 方式2
JobClient jobClient = new JobClientBuilder()
.setPropertiesConfigure("lts.properties")
.setJobCompletedHandler(new JobCompletedHandlerImpl())
.build();

submitCronJob(jobClient);
submitRepeatJob(jobClient);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
lts.jobclient.cluster-name=test_cluster
lts.jobclient.registry-address=zookeeper://127.0.0.1:2181
lts.jobclient.node-group=test_jobClient
lts.jobclient.use-retry-client=true
lts.jobclient.configs.job.fail.store=mapdb


#LTS.JOBCLIENT.CLUSTER-NAME=test_cluster
#LTS.JOBCLIENT.REGISTRY-ADDRESS=zookeeper://127.0.0.1:2181
#LTS.JOBCLIENT.NODE-GROUP=test_jobClient
#LTS.JOBCLIENT.USE-RETRY-CLIENT=true
#LTS.JOBCLIENT.CONFIGS.job.fail.store=mapdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>lts-example-jobclient</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>lts-example-jobclient-spring-annotation</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${springframework.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.ltsopensource.example;

import com.github.ltsopensource.jobclient.JobClient;
import com.github.ltsopensource.spring.JobClientFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author Robert HG ([email protected]) on 4/22/16.
*/
@Configuration
public class JobClientConfig {

@Bean(name = "jobClient")
public JobClient getJobClient() throws Exception {
JobClientFactoryBean factoryBean = new JobClientFactoryBean();
factoryBean.setLocations("lts.properties");
factoryBean.afterPropertiesSet();
factoryBean.start();
return factoryBean.getObject();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.ltsopensource.example;

import com.github.ltsopensource.core.commons.utils.CollectionUtils;
import com.github.ltsopensource.core.domain.JobResult;
import com.github.ltsopensource.jobclient.support.JobCompletedHandler;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
* @author Robert HG ([email protected]) on 4/17/16.
*/
public class JobCompletedHandlerImpl implements JobCompletedHandler {

@Override
public void onComplete(List<JobResult> jobResults) {
// 任务执行反馈结果处理
if (CollectionUtils.isNotEmpty(jobResults)) {
for (JobResult jobResult : jobResults) {
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 任务执行完成:" + jobResult);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.ltsopensource.example;

import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.jobclient.JobClient;
import com.github.ltsopensource.jobclient.domain.Response;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* @author Robert HG ([email protected]) on 4/22/16.
*/
public class Main {

public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("/lts-jobclient.xml");

JobClient jobClient = (JobClient) context.getBean("jobClient");

Job job = new Job();
job.setTaskId("t_realtime_5556666");
job.setParam("shopId", "1122222221");
job.setTaskTrackerNodeGroup("test_trade_TaskTracker");
job.setNeedFeedback(true);
job.setReplaceOnExist(true); // 当任务队列中存在这个任务的时候,是否替换更新
Response response = jobClient.submitJob(job);
System.out.println(response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

log4j.rootLogger=INFO,stdout

log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%-5p] [%d{HH:mm:ss}] %c - %m%n
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd"
>

<context:component-scan base-package="com.github.ltsopensource.example"/>
<context:annotation-config/>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
lts.jobclient.cluster-name=test_cluster
lts.jobclient.registry-address=zookeeper://127.0.0.1:2181
lts.jobclient.node-group=test_jobClient
lts.jobclient.use-retry-client=true
lts.jobclient.configs.job.fail.store=mapdb


#LTS.JOBCLIENT.CLUSTER-NAME=test_cluster
#LTS.JOBCLIENT.REGISTRY-ADDRESS=zookeeper://127.0.0.1:2181
#LTS.JOBCLIENT.NODE-GROUP=test_jobClient
#LTS.JOBCLIENT.USE-RETRY-CLIENT=true
#LTS.JOBCLIENT.CONFIGS.job.fail.store=mapdb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<parent>
<artifactId>lts-example-jobclient</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.7.1</version>
<version>1.6.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>lts-example-jobclient-spring</artifactId>
<artifactId>lts-example-jobclient-spring-xml</artifactId>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@
http://www.springframework.org/schema/context/spring-context-4.0.xsd"
>

<!--<bean id="jobClient" class="com.github.ltsopensource.spring.JobClientFactoryBean" init-method="start">-->
<!--<property name="clusterName" value="test_cluster"/>-->
<!--<property name="registryAddress" value="zookeeper://127.0.0.1:2181"/>-->
<!--<property name="nodeGroup" value="test_jobClient"/>-->
<!--<property name="jobCompletedHandler">-->
<!--<bean class="com.github.ltsopensource.example.spring.JobCompletedHandlerImpl"/>-->
<!--</property>-->
<!--<property name="configs">-->
<!--<props>-->
<!--<prop key="job.fail.store">mapdb</prop>-->
<!--</props>-->
<!--</property>-->
<!--</bean>-->

<bean id="jobClient" class="com.github.ltsopensource.spring.JobClientFactoryBean" init-method="start">
<property name="clusterName" value="test_cluster"/>
<property name="registryAddress" value="zookeeper://127.0.0.1:2181"/>
<property name="nodeGroup" value="test_jobClient"/>
<property name="locations" value="lts.properties"/>
<property name="jobCompletedHandler">
<bean class="com.github.ltsopensource.example.spring.JobCompletedHandlerImpl"/>
</property>
<property name="configs">
<props>
<prop key="job.fail.store">mapdb</prop>
</props>
</property>
</bean>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
lts.jobclient.cluster-name=test_cluster
lts.jobclient.registry-address=zookeeper://127.0.0.1:2181
lts.jobclient.node-group=test_jobClient
lts.jobclient.use-retry-client=true
lts.jobclient.configs.job.fail.store=mapdb


#LTS.JOBCLIENT.CLUSTER-NAME=test_cluster
#LTS.JOBCLIENT.REGISTRY-ADDRESS=zookeeper://127.0.0.1:2181
#LTS.JOBCLIENT.NODE-GROUP=test_jobClient
#LTS.JOBCLIENT.USE-RETRY-CLIENT=true
#LTS.JOBCLIENT.CONFIGS.job.fail.store=mapdb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobclient</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.7.1</version>
<version>1.6.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>lts-example-jobclient-springboot</artifactId>
Expand Down
5 changes: 3 additions & 2 deletions lts-example-jobclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
<parent>
<artifactId>lts-examples</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.7.1</version>
<version>1.6.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<modules>
<module>lts-example-jobclient-springboot</module>
<module>lts-example-jobclient-spring</module>
<module>lts-example-jobclient-spring-xml</module>
<module>lts-example-jobclient-java</module>
<module>lts-example-jobclient-spring-annotation</module>
</modules>
<artifactId>lts-example-jobclient</artifactId>

Expand Down
2 changes: 1 addition & 1 deletion lts-example-jobtracker/lts-example-jobtracker-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>lts-example-jobtracker</artifactId>
<groupId>com.github.ltsopensource</groupId>
<version>1.6.7.1</version>
<version>1.6.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
package com.github.ltsopensource.example.java;

import com.github.ltsopensource.jobtracker.JobTracker;
import com.github.ltsopensource.jobtracker.JobTrackerBuilder;

/**
* @author Robert HG ([email protected]) on 4/17/16.
*/
public class Main {

public static void main(String[] args) {
final JobTracker jobTracker = new JobTracker();
// 节点信息配置
jobTracker.setRegistryAddress("zookeeper://127.0.0.1:2181");
// jobTracker.setRegistryAddress("redis://127.0.0.1:6379");
jobTracker.setListenPort(35001); // 默认 35001
jobTracker.setClusterName("test_cluster");
// final JobTracker jobTracker = new JobTracker();
// // 节点信息配置
// jobTracker.setRegistryAddress("zookeeper://127.0.0.1:2181");
//// jobTracker.setRegistryAddress("redis://127.0.0.1:6379");
// jobTracker.setListenPort(35001); // 默认 35001
// jobTracker.setClusterName("test_cluster");
//
//// // 设置业务日志记录 mysql
//// jobTracker.addConfig("job.logger", "mysql");
//// // 任务队列用mysql
//// jobTracker.addConfig("job.queue", "mysql");
// // mysql 配置
// jobTracker.addConfig("jdbc.url", "jdbc:mysql://127.0.0.1:3306/lts");
// jobTracker.addConfig("jdbc.username", "root");
// jobTracker.addConfig("jdbc.password", "root");

final JobTracker jobTracker = new JobTrackerBuilder()
.setPropertiesConfigure("lts.properties")
.build();

// // 设置业务日志记录 mysql
// jobTracker.addConfig("job.logger", "mysql");
// // 任务队列用mysql
// jobTracker.addConfig("job.queue", "mysql");
// mysql 配置
jobTracker.addConfig("jdbc.url", "jdbc:mysql://127.0.0.1:3306/lts");
jobTracker.addConfig("jdbc.username", "root");
jobTracker.addConfig("jdbc.password", "root");
// 启动节点
jobTracker.start();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
lts.jobtracker.cluster-name=test_cluster
lts.jobtracker.listen-port=35001
lts.jobtracker.registry-address=zookeeper://127.0.0.1:2181
lts.jobtracker.configs.job.logger=mysql
lts.jobtracker.configs.job.queue=mysql
lts.jobtracker.configs.jdbc.url=jdbc:mysql://127.0.0.1:3306/lts
lts.jobtracker.configs.jdbc.username=root
lts.jobtracker.configs.jdbc.password=root
Loading

0 comments on commit e383285

Please sign in to comment.