消费者无法处理消息 - Spring Cloud Stream

时间:2021-04-29 23:27:04

标签: java json spring spring-cloud amazon-kinesis

我有一个使用 Spring Cloud Stream - Amazon Kinesis 集成的发布/订阅模型。我能够向消费者发布事件,但无法读取它们。我正在使用 PutRecordsRequest 批量发布消息。消费者正在接收一个列表,但无法读取和打印它们。我在日志中观察到以下错误,

<块引用>

org.springframework.messaging.MessageHandlingException:在“MethodInvokingMessageProcessor”[org.springframework.integration.handler.MethodInvokingMessageProcessor@1063cd77]中处理消息时发生错误;嵌套异常是 java.lang.ClassCastException: class com.amazonaws.services.kinesis.model.Record cannot be cast to class com.org.project.application.data.SomeEvent (com.amazonaws.services.kinesis.model.Record and com.org.project.application.data.SomeEvent 位于加载程序“app”的未命名模块中) 在 org.springframework.integration.support.utils.IntegrationUtils.wrapInHandlingExceptionIfNecessary(IntegrationUtils.java:191) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:111) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:95) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:127) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:177) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:115) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:133) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:106) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:453) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:403) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187) ~[spring-messaging-5.2.12.RELEASE.jar:5.2.12.RELEASE] 在 org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166) ~[spring-messaging-5.2.12.RELEASE.jar:5.2.12.RELEASE] 在 org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47) ~[spring-messaging-5.2.12.RELEASE.jar:5.2.12.RELEASE] 在 org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109) ~[spring-messaging-5.2.12.RELEASE.jar:5.2.12.RELEASE] 在 org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:198) ~[spring-integration-core-5.2.11.RELEASE.jar:5.2.11.RELEASE] 在 org.springframework.integration.aws.inbound.kinesis.KinesisMessageDrivenChannelAdapter.access$4800(KinesisMessageDrivenChannelAdapter.java:102) ~[spring-integration-aws-2.3.5.RELEASE.jar:na] 在 org.springframework.integration.aws.inbound.kinesis.KinesisMessageDrivenChannelAdapter$ShardConsumer.performSend(KinesisMessageDrivenChannelAdapter.java:1308) ~[spring-integration-aws-2.3.5.RELEASE.jar:na] 在 org.springframework.integration.aws.inbound.kinesis.KinesisMessageDrivenChannelAdapter$ShardConsumer.processMultipleRecords(KinesisMessageDrivenChannelAdapter.java:1254) ~[spring-integration-aws-2.3.5.RELEASE.jar:na] 在 org.springframework.integration.aws.inbound.kinesis.KinesisMessageDrivenChannelAdapter$ShardConsumer.processRecords(KinesisMessageDrivenChannelAdapter.java:1209) ~[spring-integration-aws-2.3.5.RELEASE.jar:na] 在 org.springframework.integration.aws.inbound.kinesis.KinesisMessageDrivenChannelAdapter$ShardConsumer.lambda$processTask$1(KinesisMessageDrivenChannelAdapter.java:1083) ~[spring-integration-aws-2.3.5.RELEASE.jar:na] 在 org.springframework.integration.aws.inbound.kinesis.KinesisMessageDrivenChannelAdapter$ConsumerInvoker.run(KinesisMessageDrivenChannelAdapter.java:1401) ~[spring-integration-aws-2.3.5.RELEASE.jar:na] 在 java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na] 在 java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na] 在 java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]

 @Bean
public Consumer<List<SomeEvent>> someConsumerBatchProcessing(){
    return someEvents -> {
        logger.info("An SomeEvent has been received from Kinesis " + someEvents.toString());
        eventLogger.logEvent("Some event received from Kinesis" + someEvents.toString());
        System.out.println("Consumer List Size: "+someEvents.size()); //receiving the size perfectly fine
        System.out.println("Some Objects in Consumer Class"+someEvents.get(0).toString()); //receiving the java.lang.ClassCastException here
        System.out.println("Some Objects in Consumer Class Without toString"+someEvents.get(0));
        consumerMethodThrowExceptionBatch();
    };
}

0 个答案:

没有答案