xxljob 整合 及遇到的问题

xxljob 整合 及遇到的问题

xxljob 整合 及遇到的问题_第1张图片

整合job端

阅读文档

https://www.xuxueli.com/xxl-job/ 认真的 把文档看几遍 ,因为 我是之前看过,也快忘了,又看了一遍

导入jar包



    com.xuxueli
    xxl-job-core
    2.1.1-SNAPSHOT

配置文件

xxl:
  job:
    executor:
      logpath: ./logs/producer-job/jobhandler
      appname: skuexpiredate-job
      port: 9999
      logretentiondays: 3
      ip:
    admin:
      addresses: http://127.0.0.1:9998/xxl-job-admin
    accessToken:

编写 jobHandler

package com.yyb.ch.jobhandler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@JobHandler(value="SkuExpireDateJobHandler")
@Component
public class SkuExpireDateJobHandler extends IJobHandler {
    private static final Logger logger = LoggerFactory.getLogger(SkuExpireDateJobHandler.class);

   /* @Autowired
    private MasterOrderService masterOrderService;*/

    @Override
    public ReturnT execute(String param) throws Exception {
        long startTime=System.currentTimeMillis();

        XxlJobLogger.log("执行 sku 出库 任务");
        long endTime=System.currentTimeMillis();
        XxlJobLogger.log("同步使用时间:"+(endTime-startTime));

        XxlJobLogger.log("执行 sku 出库 任务end");
        //logger.info("同步使用时间:"+(endTime-startTime));
        return SUCCESS;
    }

}

xxl-job-amdin

将xxl-job-amdin 从Gitee 拉取下来 并启动

https://gitee.com/xuxueli0323/xxl-job

导入idea 中 然后启动 顺便看看 目录结构

配置文件

### web
server.port=9998
server.context-path=/xxl-job-admin

### resources
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/

### freemarker
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.suffix=.ftl
spring.freemarker.charset=UTF-8
spring.freemarker.request-context-attribute=request
spring.freemarker.settings.number_format=0.##########

### mybatis
mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml

### xxl-job, datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?Unicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
spring.datasource.tomcat.max-wait=10000
spring.datasource.tomcat.max-active=30
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=SELECT 1
spring.datasource.tomcat.validation-interval=30000

### xxl-job email
spring.mail.host=smtp.qq.com
spring.mail.port=25
spring.mail.username=
spring.mail.password=
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

### xxl-job, access token
xxl.job.accessToken=

### xxl-job, i18n (default empty as chinese, "en" as english)
xxl.job.i18n=

其他的没有做改动

启动后

xxljob 整合 及遇到的问题_第2张图片

配置执行器

xxljob 整合 及遇到的问题_第3张图片

配置任务管理

xxljob 整合 及遇到的问题_第4张图片

遇到的问题

 任务触发类型:Cron触发
调度机器:192.168.0.199
执行器-注册方式:自动注册
执行器-地址列表:[192.168.31.61:9999]
路由策略:第一个
阻塞处理策略:单机串行
任务超时时间:0
失败重试次数:0

\>>>>>>>>>>>触发调度<<<<<<<<<<<
触发调度:
address:192.168.31.61:9999
code:500
msg:com.xxl.rpc.util.XxlRpcException: io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.31.61:9999 at com.xxl.rpc.remoting.invoker.reference.XxlRpcReferenceBean$1.invoke(XxlRpcReferenceBean.java:227) at com.sun.proxy.$Proxy84.run(Unknown Source) at com.xxl.job.admin.core.trigger.XxlJobTrigger.runExecutor(XxlJobTrigger.java:196) at com.xxl.job.admin.core.trigger.XxlJobTrigger.processTrigger(XxlJobTrigger.java:149) at com.xxl.job.admin.core.trigger.XxlJobTrigger.trigger(XxlJobTrigger.java:74) at com.xxl.job.admin.core.thread.JobTriggerPoolHelper$3.run(JobTriggerPoolHelper.java:76) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.31.61:9999 at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:267) at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38) at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:127) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:405) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:906) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ... 1 more 

错误原因

看了错误后马上明白了为啥

admin =注册中心在测试环境 服务器上

而客户端 在我本机 所以

Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /192.168.31.61:9999

解决方案

  1. 把客户端 工程 打包 在 测试环境启动
  2. 把admin 任务注册中心 放到 本地

你可能感兴趣的:(分布式)