简体   繁体   中英

ClassCastException in Spring Cloud Contract MessageVerifier using ActiveMQ

I've been playing around with Spring Cloud Contract all week. I was able to get create a producer and consumer application using Spring Cloud Stream for the messaging.

I'm trying to rework the producer side to use ActiveMQ (with Virtual Topics). I think I'm almost there. I've written my own MessageVerifier and injected that into the base class of my test. Now I'm getting:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.535 sec <<< FAILURE! - in org.springframework.cloud.contract.verifier.tests.someconsumer.MessagingTest validate_inviteContract(org.springframework.cloud.contract.verifier.tests.someconsumer.MessagingTest) Time elapsed: 0.802 sec <<< ERROR! java.lang.ClassCastException: org.apache.activemq.command.ActiveMQTextMessage cannot be cast to org.springframework.messaging.Message at org.springframework.cloud.contract.verifier.messaging.stream.ContractVerifierHelper.convert(ContractVerifierStreamAutoConfiguration.java:59) at org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging.receive(ContractVerifierMessaging.java:40) at org.springframework.cloud.contract.verifier.tests.someconsumer.MessagingTest.validate_inviteContract(MessagingTest.java:27)

I can tell from the log files that the test message is being sent, and my custom MessageVerifier is picking the message up. What step(s) am I missing?

If I define my MessageVerifier like so:

public class ConsumerMessageVerifier implements MessageVerifier< ActiveMQTextMessage>

Then that resolves the ClassCastException, but leads to other problems an 'Application Failed to Start' error:

Description: Parameter 0 of method contractVerifierMessaging in org.springframework.cloud.contract.verifier.messaging.integration.ContractVerifierIntegrationConfiguration required a bean of type 'org.springframework.cloud.contract.verifier.messaging.MessageVerifier' that could not be found. - Bean method 'contractVerifierMessageExchange' not loaded because @ConditionalOnClass did not find required class 'org.springframework.amqp.rabbit.core.RabbitTemplate' - Bean method 'contractVerifierMessageExchange' not loaded because @ConditionalOnClass did not find required class 'org.apache.camel.Message' - Bean method 'contractVerifierMessageExchange' in 'ContractVerifierIntegrationConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.cloud.contract.verifier.messaging.MessageVerifier; SearchStrategy: all) found bean 'consumerMessageVerifier' - Bean method 'contractVerifierMessageExchange' in 'NoOpContractVerifierAutoConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.cloud.contract.verifier.messaging.MessageVerifier; SearchStrategy: all) found bean 'consumerMessageVerifier' - Bean method 'contractVerifierMessageExchange' not loaded because @ConditionalOnProperty (stubrunner.stream.enabled=true) found different v alue in property 'stubrunner.stream.enabled'

So, I'm not sure if that's the right path or not. So my questions are:

  1. Should I be qualifying the MessageVerifier as above ?

  2. If so what step(s) are required to resolve the 'Application Failed to Start' error?

Thanks!

MessageVerifier needs to be typed. You also need ContractVerifierMessaging . You can check out the Spring Cloud Contract packages: org.springframework.cloud.contract.verifier.messaging.amqp , org.springframework.cloud.contract.verifier.messaging.stream‌​ , org.springframework.cloud.contract.verifier.messaging.camel or org.springframework.cloud.contract.verifier.messaging.integr‌​ation for samples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM