使用kafka和springboot时,Dispatcher没有订阅者出现频道错误

时间:2019-12-17 14:55:00

标签: spring apache-kafka spring-cloud-stream spring-cloud-stream-binder-kafka

我正在尝试在同一应用程序的实例之间创建通信通道,并尝试在kafka spring启动流中消耗和产生相同的主题。

我的代码如下:

 public interface MessageBus {

    @Input("messagebus")
    MessageChannel messageread();

    @Output("messagebus")
    MessageChannel messagewrite();
   }

控制器和侦听器的配置如下:

@StreamListener("messagebus")
    public void readMessage(String input) {
        System.out.println(input.toUpperCase());

    }

@RequestMapping(value = "/appreciate/{name}", method = RequestMethod.POST, produces = "text/plain")
public String sendMessage(@PathVariable("name") String name) {
    kafkaTemplate.send("messagebus", name.toLowerCase()).toString();
    return name.toLowerCase();

}

当我通过终端运行同一应用程序的多个实例时,我希望从一个实例发送的消息将被所有其他实例接收,但是我遇到以下错误:

 o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'messagebus'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=byte[7], headers={kafka_offset=0, scst_nativeHeadersPresent=true, kafka_consumer=org.apache.kafka.clients.consumer.KafkaConsumer@e931111, deliveryAttempt=3, kafka_timestampType=CREATE_TIME, kafka_receivedMessageKey=null, kafka_receivedPartitionId=0, kafka_receivedTopic=messagebus, kafka_receivedTimestamp=1576593978819, contentType=application/json, __TypeId__=[B@4f771b62, kafka_groupId=anonymous.933646a6-8237-4d25-a5df-9e0013286b1f}], failedMessage=GenericMessage [payload=byte[7], headers={kafka_offset=0, scst_nativeHeadersPresent=true, kafka_consumer=org.apache.kafka.clients.consumer.KafkaConsumer@e931111, deliveryAttempt=3, kafka_timestampType=CREATE_TIME, kafka_receivedMessageKey=null, kafka_receivedPartitionId=0, kafka_receivedTopic=messagebus, kafka_receivedTimestamp=1576593978819, contentType=application/json, __TypeId__=[B@4f771b62, kafka_groupId=anonymous.933646a6-8237-4d25-a5df-9e0013286b1f}]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:461)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:403)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109)

0 个答案:

没有答案