4. xxl-job原理-- 执行器注册问题

xxl-job: v2.0.2 原理 目录学习

  • 0. xxl-job原理
  • 1. xxl-job原理---定时任务架构
  • 2. xxl-job原理-- 调度中心
  • 3. xxl-job原理-- 执行器注册
  • 4. xxl-job原理-- 执行器注册问题
  • 5 xxl-job原理-- 执行器注册问题
  • 6. xxl-job 原理-- 调度中心注册
  • 7. xxl-job 原理-- 任务管理
  • 8. xxl-job 原理-- 任务执行或触发
  • 9. xxl-job原理-- jobthread的作用
  • 10. xxl-job原理---回调

实现自我注册

properties

executor.appName=hahaha
executor.appPort=9999

XxlJobAdminConfig

@Value("${executor.appName}")
    private String appName;

@Value("${executor.appPort}")
private int appPort;

public int getAppPort() {
        appPort = appPort > 0 ? appPort : NetUtil.findAvailablePort(9999);
        return appPort;
    }

private String getAppIp() throws UnknownHostException {
        InetAddress addr = InetAddress.getLocalHost();
        String address = "";
        if (addr.toString().indexOf("/") != -1) {
            address = addr.toString().substring((addr.toString().indexOf("/") + 1));
        } else {
            address = addr.toString();
        }
        return address;
    }

@Bean
    RegistryParam getRegistryParam() throws UnknownHostException {
        return new RegistryParam("EXECUTOR", appName, getAppIp().concat(String.valueOf(getAppPort())));
    }

    // init executor-server
    private void initRpcProvider() throws UnknownHostException, Exception {
        initRpcProvider(getAppIp(), getAppPort(), appName, null);
    }

    private void initRpcProvider(String ip, int port, String appName, String accessToken) throws Exception {
        // init, provider factory
        String address = IpUtil.getIpPort(ip, port);
        Map serviceRegistryParam = new HashMap();
        serviceRegistryParam.put("appName", appName);
        serviceRegistryParam.put("address", address);
        XxlRpcProviderFactory xxlRpcProviderFactory = new XxlRpcProviderFactory();
        xxlRpcProviderFactory = new XxlRpcProviderFactory();
        xxlRpcProviderFactory.initConfig(NetEnum.NETTY_HTTP, Serializer.SerializeEnum.HESSIAN.getSerializer(), ip, port, accessToken, XxlJobExecutor.ExecutorServiceRegistry.class, serviceRegistryParam);

        // add services
        xxlRpcProviderFactory.addService(ExecutorBiz.class.getName(), null, new ExecutorBizImpl());

        // start
        xxlRpcProviderFactory.start();
    }

tips: 这里的InitRpcProvider,指的是实现 init executor server , 后台会开启执行器注册thread, 开启执行器的server, port为9999

PS: 若你觉得可以、还行、过得去、甚至不太差的话,可以“关注”一下,就此谢过!

你可能感兴趣的:(4. xxl-job原理-- 执行器注册问题)