全部产品
云市场

前置条件

更新时间:2020-06-08 15:35:37

在开始使用任务调度产品之前,对于不同的工程类型,您必须完成以下准备:

SOFABoot 工程

  1. 下载并配置好一个 SOFABoot 工程原型。

    说明:配置步骤参见 SOFABoot 快速开始。最新版本信息参见 SOFABoot 版本说明

  2. 在 SOFABoot 工程的 pom.xml 文件中引入任务调度产品的依赖:
    1. <dependency>
    2. <groupId>com.alipay.sofa</groupId>
    3. <artifactId>scheduler-enterprise-sofa-boot-starter</artifactId>
    4. </dependency>
  3. 修改 SOFABoot 全局配置项。详见 引入 SOFA 中间件 > 添加中间件全局配置项

非 SOFABoot 工程

  1. 配置工程的 Maven settings.xml 文件:
    在本地 Maven 路径下的 settings.xml 文件中,配置 mvn.cloud.alipay.com 仓库的地址及用户名密码。配置后工程即可通过 Maven 获取该仓库中任务调度的 JAR 依赖包,不配置则无法获取到 JAR 包。

    说明:mvn.cloud.alipay.com 仓库的地址及用户名密码请 提交工单 获取。

  2. 在工程的主 pom.xml 文件中引入 antschedulerclient 的依赖。以 1.0.7 版本为例:

    1. <dependency>
    2. <groupId>com.alipay.antschedulerclient</groupId>
    3. <artifactId>antschedulerclient-core</artifactId>
    4. <version>1.0.7</version>
    5. </dependency>
    6. <dependency>
    7. <groupId>com.alipay.antschedulerclient</groupId>
    8. <artifactId>antschedulerclient-antvip</artifactId>
    9. <version>1.0.7</version>
    10. </dependency>
    11. <!-- 间接依赖 -->
    12. <dependency>
    13. <groupId>com.antcloud.antvip</groupId>
    14. <artifactId>antcloud-antvip-client</artifactId>
    15. <version>1.0.4</version>
    16. </dependency>
    17. <dependency>
    18. <groupId>com.antcloud.antvip</groupId>
    19. <artifactId>antcloud-antvip-common</artifactId>
    20. <version>1.0.4</version>
    21. </dependency>
    22. <!-- antvip-common的依赖 -->
    23. <dependency>
    24. <groupId>commons-codec</groupId>
    25. <artifactId>commons-codec</artifactId>
    26. <version>1.4</version>
    27. </dependency>
    28. <dependency>
    29. <groupId>commons-io</groupId>
    30. <artifactId>commons-io</artifactId>
    31. <version>2.2</version>
    32. </dependency>
    33. <dependency>
    34. <groupId>commons-lang</groupId>
    35. <artifactId>commons-lang</artifactId>
    36. <version>2.4</version>
    37. </dependency>
    38. <dependency>
    39. <groupId>com.alibaba</groupId>
    40. <artifactId>fastjson</artifactId>
    41. <version>1.2.50</version>
    42. </dependency>
    43. <dependency>
    44. <groupId>com.alipay.sofa.cloud</groupId>
    45. <artifactId>sdk-core</artifactId>
    46. <version>0.1</version>
    47. </dependency>
    48. <dependency>
    49. <groupId>com.alipay.sofa.common</groupId>
    50. <artifactId>sofa-common-tools</artifactId>
    51. <version>1.0.12</version>
    52. </dependency>
    53. <dependency>
    54. <groupId>com.alipay.sofa</groupId>
    55. <artifactId>bolt</artifactId>
    56. <version>1.4.1</version>
    57. </dependency>
    58. <dependency>
    59. <groupId>com.alibaba.toolkit.common</groupId>
    60. <artifactId>toolkit-common-lang</artifactId>
    61. <version>1.1.1</version>
    62. </dependency>
    63. <dependency>
    64. <groupId>com.alipay.sofa</groupId>
    65. <artifactId>hessian</artifactId>
    66. <version>3.3.0</version>
    67. </dependency>
    68. <dependency>
    69. <groupId>com.alipay.sofa.lookout</groupId>
    70. <artifactId>lookout-api</artifactId>
    71. <version>1.4.3</version>
    72. </dependency>
    73. <dependency>
    74. <groupId>com.alipay.sofa</groupId>
    75. <artifactId>tracer-core</artifactId>
    76. <version>2.1.1</version>
    77. </dependency>
    78. <dependency>
    79. <groupId>com.alipay.sofa</groupId>
    80. <artifactId>tracer-extensions</artifactId>
    81. <version>2.1.1</version>
    82. </dependency>
    83. <dependency>
    84. <groupId>com.alipay.common</groupId>
    85. <artifactId>tracer</artifactId>
    86. <version>2.1.1</version>
    87. </dependency>
    88. <dependency>
    89. <groupId>com.google.guava</groupId>
    90. <artifactId>guava</artifactId>
    91. <version>20.0</version>
    92. </dependency>
  3. 获取环境配置参数。详见 引入 SOFA 中间件 > 添加中间件全局配置项
  4. 初始化客户端 client。示例如下:

    1. @Override
    2. public void onApplicationEvent(ContextRefreshedEvent event) {
    3. try {
    4. ApplicationContext applicationContext = event.getApplicationContext();
    5. Map<String, IJobHandler> handlerBeans = applicationContext
    6. .getBeansOfType(IJobHandler.class);
    7. for (IJobHandler handler : handlerBeans.values()) {
    8. handlerList.add(handler);
    9. }
    10. // zone(cell),如果为空则认为不分zone(cell)
    11. zone = System.getProperty("com.alipay.ldc.zone");
    12. Config config = new Config(app, zone, instanceId, accessKey, securityKey);
    13. AntVipRouterConfig routerConfig = new AntVipRouterConfig();
    14. routerConfig.setEndPoint(antvipEndpoint);
    15. AntVipRouter router = new AntVipRouter(routerConfig);
    16. antSchedulerClient = new AntSchedulerClient(config, router, handlerList);
    17. antSchedulerClient.init();
    18. } catch (Throwable t) {
    19. LOGGER.error("init antschedulerclient error", t);
    20. throw new RuntimeException(t);
    21. }
    22. }