parent
eb2ed78669
commit
9f5257ea59
@ -0,0 +1,38 @@
|
||||
package com.wanhua.frameless.qp.stationv2;
|
||||
|
||||
import com.wanhua.frameless.qp.stationv2.config.QpCollectorJobConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2018-10-31 19:05:43
|
||||
*/
|
||||
public class FramelessQpStationV2CollectorApplication {
|
||||
private static Logger logger = LoggerFactory.getLogger(FramelessQpStationV2CollectorApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
// start
|
||||
QpCollectorJobConfig.getInstance().initXxlJobExecutor();
|
||||
|
||||
// Blocks until interrupted
|
||||
while (true) {
|
||||
try {
|
||||
TimeUnit.HOURS.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
// destroy
|
||||
QpCollectorJobConfig.getInstance().destroyXxlJobExecutor();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.wanhua.frameless.qp.stationv2.config;
|
||||
|
||||
|
||||
import com.wanhua.frameless.qp.stationv2.jobhandler.QpStationV2CollectorJob;
|
||||
import com.xxl.job.core.executor.impl.XxlJobSimpleExecutor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2018-10-31 19:05:43
|
||||
*/
|
||||
public class QpCollectorJobConfig {
|
||||
private static Logger logger = LoggerFactory.getLogger(QpCollectorJobConfig.class);
|
||||
|
||||
|
||||
private static QpCollectorJobConfig instance = new QpCollectorJobConfig();
|
||||
public static QpCollectorJobConfig getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private XxlJobSimpleExecutor xxlJobExecutor = null;
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
public void initXxlJobExecutor() {
|
||||
|
||||
// load executor prop
|
||||
Properties xxlJobProp = loadProperties("xxl-job-executor.properties");
|
||||
|
||||
// init executor
|
||||
xxlJobExecutor = new XxlJobSimpleExecutor();
|
||||
xxlJobExecutor.setAdminAddresses(xxlJobProp.getProperty("xxl.job.admin.addresses"));
|
||||
xxlJobExecutor.setAccessToken(xxlJobProp.getProperty("xxl.job.accessToken"));
|
||||
xxlJobExecutor.setAppname(xxlJobProp.getProperty("xxl.job.executor.appname"));
|
||||
xxlJobExecutor.setAddress(xxlJobProp.getProperty("xxl.job.executor.address"));
|
||||
xxlJobExecutor.setIp(xxlJobProp.getProperty("xxl.job.executor.ip"));
|
||||
xxlJobExecutor.setPort(Integer.valueOf(xxlJobProp.getProperty("xxl.job.executor.port")));
|
||||
xxlJobExecutor.setLogPath(xxlJobProp.getProperty("xxl.job.executor.logpath"));
|
||||
xxlJobExecutor.setLogRetentionDays(Integer.valueOf(xxlJobProp.getProperty("xxl.job.executor.logretentiondays")));
|
||||
|
||||
// registry job bean
|
||||
xxlJobExecutor.setXxlJobBeanList(Arrays.asList(new QpStationV2CollectorJob()));
|
||||
|
||||
// start executor
|
||||
try {
|
||||
xxlJobExecutor.start();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* destroy
|
||||
*/
|
||||
public void destroyXxlJobExecutor() {
|
||||
if (xxlJobExecutor != null) {
|
||||
xxlJobExecutor.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Properties loadProperties(String propertyFileName) {
|
||||
InputStreamReader in = null;
|
||||
try {
|
||||
ClassLoader loder = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
in = new InputStreamReader(loder.getResourceAsStream(propertyFileName), "UTF-8");;
|
||||
if (in != null) {
|
||||
Properties prop = new Properties();
|
||||
prop.load(in);
|
||||
return prop;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("load {} error!", propertyFileName);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
logger.error("close {} error!", propertyFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" threshold="null" debug="null">
|
||||
|
||||
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-frameless [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="file" value="./logs/xxl-job/xxl-job-executor-sample-frameless.log"/>
|
||||
<param name="append" value="true"/>
|
||||
<param name="encoding" value="UTF-8"/>
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-frameless [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="CONSOLE" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
@ -0,0 +1,17 @@
|
||||
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||
xxl.job.admin.addresses=http://172.22.62.105/internal/etl/xxl-job-admin
|
||||
|
||||
### xxl-job, access token
|
||||
xxl.job.accessToken=default_token
|
||||
|
||||
### xxl-job executor appname
|
||||
xxl.job.executor.appname=qpsy-interbase2
|
||||
### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
|
||||
xxl.job.executor.address=http://172.22.62.105
|
||||
### xxl-job executor server-info
|
||||
xxl.job.executor.ip=
|
||||
xxl.job.executor.port=19998
|
||||
### xxl-job executor log-path
|
||||
xxl.job.executor.logpath=logs/xxl-job/jobhandler
|
||||
### xxl-job executor log-retention-days
|
||||
xxl.job.executor.logretentiondays=30
|
Loading…
Reference in new issue