感谢您提前阅读。在我的主要方法中,我有一个PublishSubscribeChannel
@Bean(name = "feeSchedule")
public SubscribableChannel getMessageChannel() {
return new PublishSubscribeChannel();
}
在执行长时间运行的服务中,它会创建一个将信道注入
的费用表@Service
public class FeeScheduleCompareServiceImpl implements FeeScheduleCompareService {
@Autowired
MessageChannel outChannel;
public List<FeeScheduleUpdate> compareFeeSchedules(String oldStudyId) {
List<FeeScheduleUpdate> sortedResultList = longMethod(oldStudyId);
outChannel.send(MessageBuilder.withPayload(sortedResultList).build());
return sortedResultList;
}
}
现在这是我正在努力的部分。我想使用可完成的未来,并在未来的另一个春季bean中获取事件的有效负载。我需要将来A从消息中返回有效负载。我想创建一个ServiceActivator作为消息终点,但就像我说的那样,我需要它来为将来的A返回有效负载。
@org.springframework.stereotype.Service
public class SFCCCompareServiceImpl implements SFCCCompareService {
@Autowired
private SubscribableChannel outChannel;
@Override
public List<SFCCCompareDTO> compareSFCC(String state, int service){
ArrayList<SFCCCompareDTO> returnList = new ArrayList<SFCCCompareDTO>();
CompletableFuture<List<FeeScheduleUpdate>> fa = CompletableFuture.supplyAsync( () ->
{ //block A WHAT GOES HERE?!?!
outChannel.subscribe()
}
);
CompletableFuture<List<StateFeeCodeClassification>> fb = CompletableFuture.supplyAsync( () ->
{
return this.stateFeeCodeClassificationRepository.findAll();
}
);
CompletableFuture<List<SFCCCompareDTO>> fc = fa.thenCombine(fb,(a,b) ->{
//block C
//get in this block when both A & B are complete
Object theList = b.stream().forEach(new Consumer<StateFeeCodeClassification>() {
@Override
public void accept(StateFeeCodeClassification stateFeeCodeClassification) {
a.stream().forEach(new Consumer<FeeScheduleUpdate>() {
@Override
public void accept(FeeScheduleUpdate feeScheduleUpdate) {
returnList new SFCCCompareDTO();
}
});
}
}).collect(Collectors.toList());
return theList;
});
fc.join();
return returnList;
}
}
认为会有一个服务激活者:
@MessageEndpoint
public class UpdatesHandler implements MessageHandler{
@ServiceActivator(requiresReply = "true")
public List<FeeScheduleUpdate> getUpdates(Message m){
return (List<FeeScheduleUpdate>) m.getPayload();
}
}
答案 0 :(得分:0)
您的问题不明确,但我会尝试为您提供一些信息。
Spring Integration不提供CompletableFuture
支持,但它确实提供了异步处理和回复。
有关详细信息,请参阅Asynchronous Gateway。另请参阅Asynchronous Service Activator。
顺便提一句,{p>outChannel.subscribe()
应附带MessageHandler
回调。