简体   繁体   English

使用ActiveMQ的Spring Cloud Contract MessageVerifier中的ClassCastException

[英]ClassCastException in Spring Cloud Contract MessageVerifier using ActiveMQ

I've been playing around with Spring Cloud Contract all week. 我整个星期都在玩Spring Cloud Contract。 I was able to get create a producer and consumer application using Spring Cloud Stream for the messaging. 我能够使用Spring Cloud Stream创建用于消息传递的生产者和消费者应用程序。

I'm trying to rework the producer side to use ActiveMQ (with Virtual Topics). 我正在尝试使生产者方面使用ActiveMQ(带有虚拟主题)。 I think I'm almost there. 我想我快到了。 I've written my own MessageVerifier and injected that into the base class of my test. 我已经编写了自己的MessageVerifier并将其注入到测试的基类中。 Now I'm getting: 现在我得到:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.535 sec <<< FAILURE! 测试运行:1,失败:0,错误:1,跳过:0,经过的时间:2.535秒<<<失败! - 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! -在org.springframework.cloud.contract.verifier.tests.someconsumer.MessagingTest validate_inviteContract(org.springframework.cloud.contract.verifier.tests.someconsumer.MessagingTest)中经过的时间:0.802秒<< <<错误! 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) java.lang.ClassCastException:org.apache.activemq.command.ActiveMQTextMessage无法转换为org.springframework.cloud.cloud.contract.verifier.messaging.stream.ContractVerifierHelper.convert(ContractVerifierStreamAutoConfiguration.java:59上的org.springframework.messaging.Message )在org.springframework.cloud.contract.verifier.tests.someconsumer.MessagingTest.validate_inviteContract(MessagingTest.java:27)在org.springframework.cloud.contract.verifier.messaging.internal.ContractVerifierMessaging.receive(ContractVerifierMessaging.java:40) )

I can tell from the log files that the test message is being sent, and my custom MessageVerifier is picking the message up. 我可以从日志文件中得知正在发送测试消息,而我的自定义MessageVerifier正在接收该消息。 What step(s) am I missing? 我缺少什么步骤?

If I define my MessageVerifier like so: 如果我这样定义我的MessageVerifier:

public class ConsumerMessageVerifier implements MessageVerifier< ActiveMQTextMessage> 公共类ConsumerMessageVerifier实现MessageVerifier <ActiveMQTextMessage>

Then that resolves the ClassCastException, but leads to other problems an 'Application Failed to Start' error: 然后,这解决了ClassCastException,但导致了其他问题,即“应用程序无法启动”错误:

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. 说明:org.springframework.cloud.cloud.contract.verifier.messaging.integration.ContractVerifierIntegrationConfiguration中的方法contractVerifierMessaging的参数0需要一个类型为'org.springframework.cloud.contract.verifier.messaging.MessageVerifier'的bean。 - 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 -由于@ConditionalOnClass未找到所需的类'org.springframework.amqp.rabbit.core.RabbitTemplate',因此未加载Bean方法'contractVerifierMessageExchange'-由于@ConditionalOnClass未找到所需的类'org.apache,因此未加载Bean方法'contractVerifierMessageExchange'。 camel.Message'-未加载'ContractVerifierIntegrationConfiguration'中的Bean方法'contractVerifierMessageExchange',因为@ConditionalOnMissingBean(类型:org.springframework.cloud.contract.verifier.messaging.MessageVerifier; SearchStrategy:all)找到了bean'consumerMessageVerifier'-Bean方法'contractVerifierMessageExchange未能加载'NoOpContractVerifierAutoConfiguration'中的',因为@ConditionalOnMissingBean(类型:org.springframework.cloud.cloud.contract.verifier.messaging.MessageVerifier; SearchStrategy:all)找到了bean'consumerMessageVerifier'-Bean方法'contractVerifierMessageExchange'因为@ConditionalOnProperty(stubrunner。 stream.enabled = true)找到了不同的v alue in property 'stubrunner.stream.enabled' 同样在属性“ 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 ? 我应该像上面一样使MessageVerifier合格吗?

  2. If so what step(s) are required to resolve the 'Application Failed to Start' error? 如果是这样,则需要采取什么步骤来解决“应用程序启动失败”错误?

Thanks! 谢谢!

MessageVerifier needs to be typed. 需要输入MessageVerifier You also need ContractVerifierMessaging . 您还需要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. 您可以检查出春天的云合同包: org.springframework.cloud.contract.verifier.messaging.amqporg.springframework.cloud.contract.verifier.messaging.stream‌​org.springframework.cloud.contract.verifier.messaging.camel样本的org.springframework.cloud.contract.verifier.messaging.camelorg.springframework.cloud.contract.verifier.messaging.integr‌​ation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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