我使用了spring-cloud-starter-stream-kafka 2.1.2 相应主题的使用者已编写并部署到测试环境。 然后,我使用@conditional排除本地使用者,并且将始终出现以下错误:
@Component
@Slf4j
@Conditional(NotWindowsCondition.class)
public class TestListener {
@StreamListener(TestSink.INPUT)
org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'application-1.input'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=byte[38], headers={deliveryAttempt=3, X-B3-ParentSpanId=41e8fe9d35f75986, kafka_timestampType=CREATE_TIME, kafka_receivedTopic=user_huanxin_register, spanTraceId=1c2878998d138740, spanId=34cbd18294b7858d, spanParentSpanId=41e8fe9d35f75986, nativeHeaders={spanTraceId=[1c2878998d138740], spanId=[8654b6a6c4aa8517], spanParentSpanId=[3df3fa4e69033f5e], spanSampled=[0], X-B3-TraceId=[1c2878998d138740], X-B3-SpanId=[8654b6a6c4aa8517], X-B3-ParentSpanId=[3df3fa4e69033f5e], X-B3-Sampled=[0]}, kafka_offset=74, X-B3-SpanId=34cbd18294b7858d, scst_nativeHeadersPresent=true, kafka_consumer=org.apache.kafka.clients.consumer.KafkaConsumer@16c73ae4, X-B3-Sampled=0, X-B3-TraceId=1c2878998d138740, id=201aaf99-082b-864f-8129-de7961e03972, kafka_receivedPartitionId=0, spanSampled=0, kafka_receivedTimestamp=1559041573040, contentType=application/json, timestamp=1559041580558}]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:453)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166)
我试图找到一个配置来指定消耗或不消耗,但没有找到
所需结果:使特定环境能够使用或不使用而不会出现错误消息
答案 0 :(得分:0)
将auto-startup
属性设置为false。
@SpringBootApplication
@EnableBinding(Sink.class)
public class So56341052Application {
public static void main(String[] args) {
SpringApplication.run(So56341052Application.class, args);
}
}
@Component
@ConditionalOnProperty("is.enabled")
class Listener {
@StreamListener(Sink.INPUT)
public void listen(String in) {
}
}
is.enabled=false
spring.cloud.stream.bindings.input.consumer.auto-startup=${is.enabled}