繁体   English   中英

Spring 云 Stream 应用程序在供应商完成之前退出

[英]Spring Cloud Stream Application Exits Before Supplier Finishes

我有一个“任务”应用程序,它寿命很短,根据数据库中的状态向 Kafka 生成消息。 我正在使用 spring 云 stream 使用我的应用程序的以下格式生成消息。 我遵循Spring Cloud Stream 文档中的这种格式,将任意数据发送到 output 绑定。

private EmitterProcessor<Message<GenericRecord>> processor;

@Override
public void run(ApplicationArguments arg0) {
    // ... create Message<GenericRecord> producerRecord
    this.processor.onNext(producerRecord);
}

@Bean
public Supplier<Flux<Message<GenericRecord>>> supplier() {
    return () -> this.processor;
}

public static void main(String[] args) {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
    ctx.close();
}

应用程序运行,创建记录,运行 onNext(),然后退出。 然后我查看是否有任何消息已发布,但没有关于该主题的消息。 然后,在生成每条消息后,我添加了一个Thread.sleep(10000)并且消息最终出现在主题上。

在查看了 Reactor 的文档后,我没有看到任何明确的方法来实现这一点。 有没有办法在 Spring 应用程序退出之前等待 EmitterProcessor 完成消息发布?

你有使用EmittorProcessor的特定理由吗? 我认为这个用例可以通过使用StreamBridge来解决。 例如

@Autowired StreamBridge streamBridge;


@Override
public void run(ApplicationArguments arg0) {
    // ... create Message<GenericRecord> producerRecord
    this.streamBridge.send("process-out-0", producerRecord);
}

然后提供以下配置: spring.cloud.stream.source: process您可以在参考文档中找到有关StreamBridge的更多详细信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM