在Spring-integration-dsl中,使用publishSubscribeChannel开发主子流,该主子流集成了错误通道和回复通道。但是由于某些原因,该子流应由Cron(通过Quartz)重试, m尝试使用有效负载和标头构建消息,并通过子流通道发送消息,并且子流回复通道也设置为标头。
此处的主子流定义:
@Bean
public IntegrationFlow mainFlow(){
return IntegrationFlows.from(MainFlow.REQUEST_CHANNEL)
...........
.publishSubscribeChannel(subFlowTaskExecutor, subscribe->
subscribe.subscribe(flow->
flow.gateway(SubFlow.REQUEST_CHANNEL,
g->
{
g.errorChannel(SubFlow.ERROR_CHANNEL);
// g.replyChannel(SubFlow.REPLY_CHANNEL);
}
)))
......
.get();
}
子流回复渠道定义:
@Bean(name= SubFlow.REPLY_CHANNEL)
public MessageChannel SubflowReplyChannel(){
return new BaseDirectChannel();
}
@Bean
public IntegrationFlow subFlow() {
return IntegrationFlows.from(SubFlow.REPLY_CHANNEL)
.transform(subflowResponseTransformer())
.get();
}
Quartz执行功能:
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
..........
message = MessageBuilder.withPayload(basePayload)
.setHeader("replyChannel", SubFlow.REPLY_CHANNEL)
SubFlow.getInputChannel().send(message);
........
}