直接运行本项目中的单元测试时框架会将任务存储在本机内存中,因此实际在生产环境中需部署用于任务CURD的 ageiport-task-server
- 建立数据库表
- 未接触过Quark的开发者使用legacy打包方式,打出的runner包与SpringBootFatJar相同
mvn package -Dmaven.test.skip=true -Dquarkus.package.type=legacy-jar
- java -jar 运行Jar包,运行Jar包时可通过系统环境变量或JVM参数执行数据库等参数
建表脚本:
CREATE TABLE `agei_main_task_instance`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`app` varchar(64) NOT NULL,
`biz_key` varchar(64) DEFAULT NULL,
`biz_query` text,
`biz_task_name` varchar(64) DEFAULT NULL,
`biz_user_feature` varchar(512) DEFAULT NULL,
`biz_user_id` varchar(64) DEFAULT NULL,
`biz_user_key` varchar(64) DEFAULT NULL,
`biz_user_name` varchar(64) DEFAULT NULL,
`biz_user_org` varchar(64) DEFAULT NULL,
`biz_user_tenant` varchar(64) DEFAULT NULL,
`code` varchar(64) NOT NULL,
`data_failed_count` int DEFAULT NULL,
`data_processed_count` int DEFAULT NULL,
`data_success_count` int DEFAULT NULL,
`data_total_count` int DEFAULT NULL,
`env` varchar(64) NOT NULL,
`execute_type` varchar(64) NOT NULL,
`feature` text,
`flow_order` int DEFAULT NULL,
`flow_task_id` varchar(64) DEFAULT NULL,
`gmt_create` datetime(6) DEFAULT NULL,
`gmt_dispatch` datetime(6) DEFAULT NULL,
`gmt_execute` datetime(6) DEFAULT NULL,
`gmt_expired` datetime(6) DEFAULT NULL,
`gmt_finished` datetime(6) DEFAULT NULL,
`gmt_modified` datetime(6) DEFAULT NULL,
`gmt_start` datetime(6) DEFAULT NULL,
`host` varchar(64) DEFAULT NULL,
`log` varchar(4096) DEFAULT NULL,
`main_task_id` varchar(64) NOT NULL,
`name` varchar(64) DEFAULT NULL,
`namespace` varchar(64) NOT NULL,
`result_code` varchar(64) DEFAULT NULL,
`result_message` varchar(128) DEFAULT NULL,
`retry_times` int DEFAULT NULL,
`row_status` varchar(64) DEFAULT NULL,
`row_version` int DEFAULT NULL,
`runtime_param` text,
`status` varchar(64) NOT NULL,
`sub_failed_count` int DEFAULT NULL,
`sub_finished_count` int DEFAULT NULL,
`sub_success_count` int DEFAULT NULL,
`sub_total_count` int DEFAULT NULL,
`tenant` varchar(64) NOT NULL,
`trace_id` varchar(64) DEFAULT NULL,
`type` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_mainTaskId` (`main_task_id`),
KEY `idx_main_task` (`tenant`,`namespace`,`app`,`env`,`code`),
KEY `idx_bizUser` (`biz_user_tenant`,`biz_user_org`,`biz_user_id`,`biz_user_key`),
KEY `idx_gmt_create` (`gmt_create`),
KEY `idx_flowTaskId` (`flow_task_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `agei_sub_task_instance`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`app` varchar(64) NOT NULL,
`biz_key` varchar(64) DEFAULT NULL,
`biz_query` text,
`biz_task_name` varchar(64) DEFAULT NULL,
`biz_user_feature` varchar(512) DEFAULT NULL,
`biz_user_id` varchar(64) DEFAULT NULL,
`biz_user_key` varchar(64) DEFAULT NULL,
`biz_user_name` varchar(64) DEFAULT NULL,
`biz_user_org` varchar(64) DEFAULT NULL,
`biz_user_tenant` varchar(64) DEFAULT NULL,
`code` varchar(64) DEFAULT NULL,
`data_failed_count` int DEFAULT NULL,
`data_processed_count` int DEFAULT NULL,
`data_success_count` int DEFAULT NULL,
`data_total_count` int DEFAULT NULL,
`env` varchar(64) NOT NULL,
`execute_type` varchar(64) NOT NULL,
`feature` text,
`flow_order` int DEFAULT NULL,
`flow_task_id` varchar(64) DEFAULT NULL,
`gmt_create` datetime(6) DEFAULT NULL,
`gmt_dispatch` datetime(6) DEFAULT NULL,
`gmt_execute` datetime(6) DEFAULT NULL,
`gmt_expired` datetime(6) DEFAULT NULL,
`gmt_finished` datetime(6) DEFAULT NULL,
`gmt_modified` datetime(6) DEFAULT NULL,
`gmt_start` datetime(6) DEFAULT NULL,
`host` varchar(64) DEFAULT NULL,
`log` varchar(4096) DEFAULT NULL,
`main_task_id` varchar(64) DEFAULT NULL,
`name` varchar(64) DEFAULT NULL,
`namespace` varchar(64) NOT NULL,
`result_code` varchar(64) DEFAULT NULL,
`result_message` varchar(128) DEFAULT NULL,
`retry_times` int DEFAULT NULL,
`row_status` varchar(64) DEFAULT NULL,
`row_version` int DEFAULT NULL,
`runtime_param` text,
`status` varchar(64) NOT NULL,
`sub_task_id` varchar(64) DEFAULT NULL,
`sub_task_no` int DEFAULT NULL,
`tenant` varchar(64) NOT NULL,
`trace_id` varchar(64) DEFAULT NULL,
`type` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
KEY `idx_mainTaskId` (`main_task_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `agei_task_specification`
(
`id` bigint NOT NULL AUTO_INCREMENT,
`app` varchar(64) NOT NULL,
`creator_id` varchar(64) DEFAULT NULL,
`creator_name` varchar(64) DEFAULT NULL,
`env` varchar(64) NOT NULL,
`feature` text,
`gmt_create` datetime(6) NOT NULL,
`gmt_modified` datetime(6) NOT NULL,
`modifier_id` varchar(64) DEFAULT NULL,
`modifier_name` varchar(64) DEFAULT NULL,
`namespace` varchar(64) NOT NULL,
`owner_id` varchar(64) DEFAULT NULL,
`owner_name` varchar(64) DEFAULT NULL,
`row_status` varchar(64) NOT NULL,
`row_version` int NOT NULL,
`status` varchar(64) NOT NULL,
`task_code` varchar(64) NOT NULL,
`task_desc` varchar(128) NOT NULL,
`task_execute_type` varchar(64) NOT NULL,
`task_handler` varchar(512) NOT NULL,
`task_name` varchar(64) NOT NULL,
`task_type` varchar(64) NOT NULL,
`tenant` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
KEY `tenant_namespace_app_env_task_code` (`tenant`,`namespace`,`app`,`env`,`task_code`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
客户端需配置并连接ageiport-task-server,配置项:com.alibaba.ageiport.processor.core.AgeiPortOptions.taskServerClientOptions
默认有两个实现,在生产环境部署时我们使用HttpTaskServerClientOptions:
- 用于生产环境部署的HttpTaskServerClientOptions
com.alibaba.ageiport.processor.core.client.http.HttpTaskServerClientOptions
- 用于测试,无需部署的MemoryTaskServerClientOptions
com.alibaba.ageiport.processor.core.client.memory.MemoryTaskServerClientOptions
示例代码
AgeiPortOptions options = new AgeiPortOptions();
HttpTaskServerClientOptions clientOptions = new HttpTaskServerClientOptions();
clientOptions.setEndpoint("localhost");
options.setTaskServerClientOptions(clientOptions);
当然,你可以可以参照上述两个实现,来实现其他RPC生产环境部署的ageiport-task-server方案
运行单元测试时框架会将生成的文件存储在本机硬盘中,实际生产中我们一般会在OSS/HDFS等存储文件
框架默认提供了AliyunOSS文件存储的插件,如果需要其他OSS或文件存储支持可参考此实现
- Maven依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>ageiport-ext-file-store-aliyunoss</artifactId>
</dependency>
- 配置及初始化,设置FileStoreOptions
AgeiPortOptions options = AgeiPortOptions.debug();
AliyunOssFileStoreOptions aliyunOssFileStoreOptions = new AliyunOssFileStoreOptions();
aliyunOssFileStoreOptions.setBucketName(bucketName);
aliyunOssFileStoreOptions.setEndpoint(endpoint);
aliyunOssFileStoreOptions.setConfig(new ClientConfiguration());
DefaultCredentials credentials = new DefaultCredentials(accessKeyId, accessKeySecret);
DefaultCredentialProvider credentialProvider = new DefaultCredentialProvider(credentials);
aliyunOssFileStoreOptions.setCredentialsProvider(credentialProvider);
options.setFileStoreOptions(aliyunOssFileStoreOptions);
如果使用mvn package -Dmaven.test.skip=true -Dquarkus.package.type=legacy-jar
命令打包,则制品为Fatjar
使用如下Dockerfile,可从ageiport-task-server目录docker文件夹下"Dockerfile.legacy-jar"获取最新Dockerfile
FROM registry.access.redhat.com/ubi8/openjdk-11:1.11
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
COPY target/lib/* /deployments/lib/
COPY target/*-runner.jar /deployments/quarkus-run.jar
EXPOSE 8080
USER 185
ENV AB_JOLOKIA_OFF=""
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"