春云流集成
任务本身可能有用,但将任务整合进更大的生态系统则使它能够实现 对于更复杂的处理和编排非常有用。本节 介绍了Spring Cloud Task与Spring Cloud Stream的集成选项。
春云任务活动
Spring Cloud Task提供通过Spring Cloud流发送事件的能力
当任务通过Spring Cloud Stream频道执行时。任务监听器是
用于出版任务执行在一个名为任务事件.此功能
自动接线到任何具有春云溪流,春-云-溪-<>,
以及其类路径上的定义任务。
要禁用事件发射监听器,请设置spring.cloud.task.events.enabled属性到false. |
在定义了相应的类路径后,以下任务会输出任务执行作为
活动任务事件通道(任务开始和结束时):
@SpringBootApplication
public class TaskEventsApplication {
public static void main(String[] args) {
SpringApplication.run(TaskEventsApplication.class, args);
}
@Configuration
public static class TaskConfiguration {
@Bean
public ApplicationRunner applicationRunner() {
return new ApplicationRunner() {
@Override
public void run(ApplicationArguments args) {
System.out.println("The ApplicationRunner was executed");
}
};
}
}
}
| 绑定器实现也必须在类路径上。 |
| 示例任务事件应用可在示例模块中找到 春云任务项目的介绍,在这里。 |
Spring Session活动
当通过任务执行 Spring Batch 作业时,Spring Cloud 任务可以配置为 根据春季批次中可用的听众数量发送信息信息。 具体来说,每个批处理作业中自动配置了以下的 Spring Batch 监听器 并在Spring运行时,在相关的Spring云流频道上发送消息 云端任务:
-
JobExecutionListener倾听作业-执行-事件 -
StepExecutionListener倾听步骤执行事件 -
ChunkListener(分块听众)倾听区块事件 -
项目阅读听者倾听项目-读取-事件 -
ItemProcessListener倾听项目-过程-事件 -
ItemWriteListener倾听物品-写入-事件 -
跳过听众倾听跳过事件
这些监听器会自动配置为任意摘要工作当适当时
Beans(a工作以及一个任务生命周期监听器)存在于语境中。配置为
收听这些事件的处理方式与其他春季绑定相同
Cloud Stream 频道已经完成了。我们的任务(运行批处理作业的任务)作为一个源,监听应用作为以下几个处理器或者沉.
一个例子是,应用程序监听作业-执行-事件渠道
为了工作开始和结束。要配置监听应用,你会
将输入配置为作业-执行-事件如下:
spring.cloud.stream.bindings.input.destination=job-execution-events
| 绑定器实现也必须在类路径上。 |
| 批处理事件的示例应用可在样本模块中找到 春云任务项目的介绍,在这里。 |
向不同通道发送批处理事件
Spring Cloud Task为批处理事件提供的选项之一是能够更改
特定听众可以向其发送消息的通道。为此,可以使用
配置如下:spring.cloud.stream.bindings.<the channel>.destination=<new destination>.例如
如果StepExecutionListener需要将消息发送到另一个名为我的步执行事件而不是默认步骤执行事件,你可以添加
配置如下:
spring.cloud.task.batch.events.step-execution-events-binding-name=my-step-execution-events。
禁用批处理事件
要禁用所有批处理事件的监听器功能,请使用以下方式 配置:
spring.cloud.task.batch.events.enabled=false
要禁用特定的批处理事件,请使用以下配置:
spring.cloud.task.batch.events.<batch event listener>.enabled=false:
以下列表显示了您可以禁用的个人听众:
spring.cloud.task.batch.events.job-execution.enabled=false
spring.cloud.task.batch.events.step-execution.enabled=false
spring.cloud.task.batch.events.chunk.enabled=false
spring.cloud.task.batch.events.item-read.enabled=false
spring.cloud.task.batch.events.item-process.enabled=false
spring.cloud.task.batch.events.item-write.enabled=false
spring.cloud.task.batch.events.skip.enabled=false
批次事件的发射顺序
默认情况下,批处理事件有Ordered.LOWEST_PRECEDENCE.要改变该值(对于
例如,对5),使用以下配置:
spring.cloud.task.batch.events.job-execution-order=5
spring.cloud.task.batch.events.step-execution-order=5
spring.cloud.task.batch.events.chunk-order=5
spring.cloud.task.batch.events.item-read-order=5
spring.cloud.task.batch.events.item-process-order=5
spring.cloud.task.batch.events.item-write-order=5
spring.cloud.task.batch.events.skip-order=5