Spring Cloud Contract和普通Spring AMQP [英] Spring Cloud Contract and plain Spring AMQP

查看:122
本文介绍了Spring Cloud Contract和普通Spring AMQP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在我们的Spring Boot项目中使用普通的 Spring AMQP .

We are using plain Spring AMQP in our spring boot projects.

我们要确保我们的消息使用者可以针对真实消息进行测试,而避免针对静态测试消息进行测试.

We want to make sure that our message consumers can test against real messages and avoid to test against static test messages.

因此,我们的生产者可以在测试阶段生成消息摘要,以供消费者测试使用,以确保它针对最新消息版本进行测试,并查看生产者中的更改是否破坏了消费者.

Thus our producers could generate message snippets in a test phase that can be picked up by the consumer test to make sure it tests against the latest message version and see if changes in the producer break the consumer.

Spring Cloud Contract 似乎正是这样做的.那么有没有办法将Spring Cloud Contract与Spring Amqp集成在一起?任何向哪个方向前进的提示将不胜感激.

It seems like Spring Cloud Contract does exactly that. So is there a way to integrate spring cloud contract with spring amqp? Any hints in which direction to go would be highly appreciated.

推荐答案

实际上,我们不开箱即用,但您可以自己设置.在自动生成的测试中,我们使用接口来接收和发送消息,因此 您可以实现自己的使用spring-amqp的类.消费者方(存根运行器)也是如此.您需要做的是实现并注册一个 生产者和消费者的org.springframework.cloud.contract.verifier.messaging.MessageVerifier类型.这应该起作用,因为我们在自动生成的测试中正在执行的操作是@Inject MessageVerifier 因此,如果您注册自己的bean,它将起作用.

Actually we don't support it out of the box but you can set it up yourself. In the autogenerated tests we're using an interface to receive and send messages so you could implement your own class that uses spring-amqp. The same goes for the consumer side (the stub runner). What you would need to do is to implement and register a bean of org.springframework.cloud.contract.verifier.messaging.MessageVerifier type for both producer and consumer. This should work cause what we're doing in the autogenerated tests is that we @Inject MessageVerifier so if you register your own bean it will work.

更新: 正如@Mathias所说,Spring Cloud Contract https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_stub_runner_spring_amqp

UPDATE: As @Mathias has mentioned it, the AMQP support is already there in Spring Cloud Contract https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_stub_runner_spring_amqp

这篇关于Spring Cloud Contract和普通Spring AMQP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆