以下是我对kafka侦听器的方法定义,如果接收到有效负载的空字符串或空字符串,我想我将收到错误消息...您能帮忙吗?
@KafkaListener(topics = "${kafka.consumer-topic-name.reservation}", groupId = "${kafka.consumer-group-id.test}",
containerFactory = "kafkaListenerContainerFactory",autoStartup = "${kafka.auto-start.consumer.tets}")
public void consumeReservation(String payload, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic,
@Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String kafkaKey) {}
[org.springframework.kafka.KafkaListenerEndpointContainer #0-0-C-1] ERROR o.s.k.l.SeekToCurrentErrorHandler - Backoff none exhausted for ConsumerRecord(topic = test_topic, partition = 0, leaderEpoch = 2, offset = 453473, CreateTime = 1601962346576, serialized key size = 41, serialized value size = -1, headers = RecordHeaders(headers = [RecordHeader(key = OPERATION, value = [68, 69, 76, 69, 84, 69]), RecordHeader(key = __Key_TypeId__, value = [99, 108, 75, 101, 121])], isReadOnly = false), key = {
"orgId": "1",
"orderId": "U4000024004"}, value = null)
org.springframework.kafka.listener.ListenerExecutionFailedException:侦听器方法无法与传入消息一起调用 端点处理程序详细信息: 方法[public void com.demo.test.analytics.testanalytics.consumer.FLReservationKafkaConsumer.consumeReservation(java.lang.String,java.lang.String,java.lang.String)] Bean [com.demo.test.analytics.testanalytics.consumer.FLReservationKafkaConsumer @ 731702d1]; 嵌套异常是org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException:无法解析公共void com.demo.test.analytics.testanalytics.consumer.FLReservationKafkaConsumer.consumeReservation(java.lang.String, java.lang.String,java.lang.String):1个错误:[对象'payload'中的错误:codes []; arguments []; 默认消息[有效负载值不能为空] ],失败消息= GenericMessage [有效载荷= org.springframework.kafka.support.KafkaNull @ 2d99561c,标头= { Key_TypeId = [B @ 19a2dc5f,kafka_offset = 453473,OPERATION = [B @ 7d75c01a,kafka_consumer = org.apache.kafka.clients.consumer.KafkaConsumer @ 363f44ef,kafka_timestampType = CREATE_TIME = { “ orgId”:“ 1”, “ orderId”:“ U4000024004” },kafka_receivedTopic = test_1order,kafka_receivedTimestamp = 1601962346576,kafka_groupId = Reservation_group_id }];嵌套的异常是org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException:无法解析公共无效com.demo.test.analytics.testanalytics.consumer.FLReservationKafkaConsumer.consumeReservation(java。 .String,java.lang.String,java.lang.String):1个错误:[对象“有效载荷”中的错误:代码[];参数[]; 默认消息[有效负载值不能为空] ], failedMessage = GenericMessage [payload = org.springframework.kafka.support.KafkaNull @ 2d99561c,标头= { Key_TypeId = [B @ 19a2dc5f,kafka_offset = 453473,OPERATION = [B @ 7d75c01a,kafka_consumer = org.apache.kafka.clients.consumer.KafkaConsumer @ 363f44ef,kafka_timestampType = CREATE_TIME = { “ orgId”:“ 1”, “ orderId”:“ U4000024004” },kafka_receivedTopic = test_1order,kafka_receivedTimestamp = 1601962346576,kafka_groupId = Reservation_group_id }] 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.decorateException(KafkaMessageListenerContainer.java:1925)处 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.invokeErrorHandler(KafkaMessageListenerContainer.java:1913) 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.doInvokeRecordListener(KafkaMessageListenerContainer.java:1812)处 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.doInvokeWithRecords(KafkaMessageListenerContainer.java:1739) 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.invokeRecordListener(KafkaMessageListenerContainer.java:1636) 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:1366)处 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:1082) 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.run(KafkaMessageListenerContainer.java:990) 在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511) 在java.util.concurrent.FutureTask.run(FutureTask.java:266) 在java.lang.Thread.run(Thread.java:748) 引起原因:org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException:无法解析公共void com.demo.test.analytics.testanalytics.consumer.FLReservationKafkaConsumer.consumeReservation(java.lang.String, java.lang.String,java.lang.String):1个错误:[对象'payload'中的错误:codes []; arguments []; 默认消息[有效负载值不能为空] ] 在org.springframework.messaging.handler.annotation.support.PayloadMethodArgumentResolver.resolveArgument(PayloadMethodArgumentResolver.java:122) 在org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor $ KafkaNullAwarePayloadArgumentResolver.resolveArgument(KafkaListenerAnnotationBeanPostProcessor.java:901)处 在org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:117) 在org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:148)处 在org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:116) 在org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:48) 在org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:329) 在org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:86)处 在org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:51) 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.doInvokeOnMessage(KafkaMessageListenerContainer.java:1880) 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.invokeOnMessage(KafkaMessageListenerContainer.java:1862) 在org.springframework.kafka.listener.KafkaMessageListenerContainer $ ListenerConsumer.doInvokeRecordListener(KafkaMessageListenerContainer.java:1799)处 ... 8个通用框架省略
答案 0 :(得分:2)
您需要指定不需要有效负载。
@Payload(required = false) String payload, ...