Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot @消息通道的后构造和自动连接_Spring Boot_Apache Kafka_Spring Cloud Stream - Fatal编程技术网

Spring boot @消息通道的后构造和自动连接

Spring boot @消息通道的后构造和自动连接,spring-boot,apache-kafka,spring-cloud-stream,Spring Boot,Apache Kafka,Spring Cloud Stream,我有一个问题,春天云流。问题是,我有一个bean,它将在Kafka创建后立即写入(用@PostConstruct注释的方法),因此我自动连接适当的MessageChannel,并在application.yml中设置目标和绑定器属性。事情是这样的: @Component @RequiredArgsConstructor public class Sender { private final MessageChannel output; @PostConstruct pu

我有一个问题,春天云流。问题是,我有一个bean,它将在Kafka创建后立即写入(用@PostConstruct注释的方法),因此我自动连接适当的MessageChannel,并在application.yml中设置目标和绑定器属性。事情是这样的:

@Component
@RequiredArgsConstructor
public class Sender
{
    private final MessageChannel output;

    @PostConstruct
    public void start()
    {
       output.send(new GenericMessage("Hello world");  
    }
}
和应用程序.yml

spring:
    cloud:
        stream:
            bindings:
              output:
                destination: someData
                binder: kafka
我还具有以下依赖项:

- spring-cloud-stream-reactive
- reactor-core
- spring-cloud-starter-stream-kafka
项目本身正在启动,但在尝试写入
start()
方法中的
output
时出现以下异常:

Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
是因为卡夫卡·宾德还没有成功绑定频道还是怎么了?如果是的话,还有什么替代方法


提前谢谢。

您不能从
@PostConstruct
中执行此操作。现在太早了。其他组件可能尚未初始化


您必须将发送逻辑移动到
SmartLifecycle.start()
实现中。

我就是这么想的。然后将尝试使用SmartLifecycle.start()。谢谢