GoogleCloudPlatform / spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Apache License 2.0
429 stars 319 forks source link

PubSubDeadLetterTopicSampleAppIntegrationTest failed with cast class exception #3139

Closed ldetmer closed 3 months ago

ldetmer commented 3 months ago

Error running PubSubDeadLetterTopicSampleAppIntegrationTest: testSample_deadLetterHandling

08:24:25.893 [global-gcp-pubsub-subscriber1] WARN  c.g.c.s.p.i.i.PubSubInboundChannelAdapter - error occurred in message handler [org.springframework.cloud.stream.function.FunctionConfiguration$FunctionToDestinationBinder$1@68347216]
08:24:29.895 [global-gcp-pubsub-subscriber3] ERROR o.s.i.handler.LoggingHandler - org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.cloud.stream.function.FunctionConfiguration$FunctionToDestinationBinder$1@68347216], failedMessage=GenericMessage [payload=byte[127], headers=***id=47898e41-b4de-a94b-a74d-d86064f5ffe0, contentType=application/json, gcp_pubsub_original_message=PushedAcknowledgeablePubsubMessage***projectId='spring-cloud-gcp-ci', subscriptionName='anonymous.my-main-topic.32f1ddf2-791f-410f-bf55-dfd4ffd5b58b', message=data: "***\"body\":\"test message 5d63cca5-980e-4e83-ae2e-4eb14f459c65\",\"username\":\"testUserName\",\"createdAt\":[2024,8,19,8,24,6,337013596]***"
attributes ***
  key: "contentType"
  value: "application/json"
***
attributes ***
  key: "googclient_deliveryattempt"
  value: "3"
***
message_id: "11994779617011169"
publish_time ***
  seconds: 1724055846
  nanos: 468000000
***
***, googclient_deliveryattempt=3, timestamp=1724055869894***]
    at org.springframework.integration.support.utils.IntegrationUtils.wrapInHandlingExceptionIfNecessary(IntegrationUtils.java:191)
    at org.springframework.integration.handler.AbstractMessageHandler.doHandleMessage(AbstractMessageHandler.java:108)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:132)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:148)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:121)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:72)
    at org.springframework.integration.channel.AbstractMessageChannel.sendInternal(AbstractMessageChannel.java:390)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:334)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:304)
    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)
    at org.springframework.integration.endpoint.MessageProducerSupport.lambda$sendMessage$1(MessageProducerSupport.java:262)
    at io.micrometer.observation.Observation.observe(Observation.java:499)
    at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:262)
    at com.google.cloud.spring.pubsub.integration.inbound.PubSubInboundChannelAdapter.consumeMessage(PubSubInboundChannelAdapter.java:146)
    at com.google.cloud.spring.pubsub.core.subscriber.PubSubSubscriberTemplate.lambda$subscribeAndConvert$1(PubSubSubscriberTemplate.java:172)
    at com.google.cloud.pubsub.v1.MessageDispatcher$3.run(MessageDispatcher.java:514)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.ClassCastException: class [B cannot be cast to class com.example.UserMessage ([B is in module java.base of loader 'bootstrap'; com.example.UserMessage is in unnamed module of loader 'app')
    at com.example.SinkExample.lambda$logUserMessage$1(SinkExample.java:38)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.invokeConsumer(SimpleFunctionRegistry.java:1063)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.doApply(SimpleFunctionRegistry.java:761)
    at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:592)
    at org.springframework.cloud.stream.function.PartitionAwareFunctionWrapper.apply(PartitionAwareFunctionWrapper.java:92)
    at org.springframework.cloud.stream.function.FunctionConfiguration$FunctionWrapper.apply(FunctionConfiguration.java:823)
    at org.springframework.cloud.stream.function.FunctionConfiguration$FunctionToDestinationBinder$1.handleMessageInternal(FunctionConfiguration.java:654)
    at org.springframework.integration.handler.AbstractMessageHandler.doHandleMessage(AbstractMessageHandler.java:105)
    ... 24 more

08:24:29.895 [global-gcp-pubsub-subscriber3] WARN  c.g.c.s.p.i.i.PubSubInboundChannelAdapter - Sending Spring message [11994779617011169] failed; message neither acked nor nacked.
08:24:29.896 [global-gcp-pubsub-subscriber3] WARN  c.g.c.s.p.i.i.PubSubInboundChannelAdapter - error occurred in message handler [org.springframework.cloud.stream.function.FunctionConfiguration$FunctionToDestinationBinder$1@68347216]
"
to contain:
  "Nacking message (attempt 1)"  within 1 minutes.
08:24:33:685 [INFO] 
Error: 3:685 [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
08:24:33:685 [INFO] 
08:24:33:685 [INFO] 
08:24:33:686 [INFO] --- failsafe:3.2.5:verify (default) @ spring-cloud-gcp-pubsub-stream-dead-letter-sample ---
08:24:33:688 [INFO] ------------------------------------------------------------------------
ldetmer commented 3 months ago

Note this is a known issue with spring-cloud-stream and a fix is already committed. The work around is posted here

ldetmer commented 3 months ago

Fixed in commit: ae3626a