kafka涉及微服务架构时如何实现合约测试? [英] How to implement contract testing when kafka is involved in microservice architecture?

查看:35
本文介绍了kafka涉及微服务架构时如何实现合约测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在做一个项目,我们在微服务架构中实现了 kafka.您是否成功地使用 pact-jvm 为 mS 到 kafka 主题交互创建了合同测试用例?

I am currently working on a project where we have kafka implementation in micro service architecture. Were you successful in creating contract test cases for mS to kafka topic interaction please using pact-jvm ?

我的实现是 microservice1 将消息发布到 REST 客户端,然后再将消息发布到 Kafka 主题.microservice2 使用 GET 方法从 Kafka Topic 中检索消息.

My implementation is microservice1 publishes a message to a REST Client which in turn posts the message to Kafka Topic. microservice2 uses GET method to retrieve messages from the Kafka Topic.

推荐答案

Pact-JVM 支持 Message Pacts,它封装了通过某种机制(通常是消息队列)使用(一种方式)的消息.思路是通过consumer test来测试consumer代码是否可以消费消息,然后验证provider生成了合适的消息.测试中没有使用实际的消息队列.

Pact-JVM supports Message Pacts, which encapsulate a message that is consumed (one way) over some mechanism, normally a message queue. The idea is to test the consumer code can consume the message via a consumer test, and then verify that the provider generates an appropriate message. The actual message queue is not used in the test.

这最初是为了对通过 Kafka 消息队列进行通信的微服务应用合同测试而开发的.

This was originally developed to apply contract tests for micro-services communicating over a Kafka message queue.

测试分两部分完成,就像请求-响应协议测试一样,除了消费者在消费者协议测试期间读取消息,如果成功则写入协议文件.然后调用提供程序代码以生成一条消息,并将其与协议文件中的内容进行比较.

The tests are done in two parts, just like Request-Response Pact tests, except the Consumer reads the message during the consumer pact test and if successful a pact file is written. Then the provider code is called to generate a message, and that is compared to what is in the pact file.

Pact-JVM 文档的相关部分是:

The relevant sections of the Pact-JVM docs are:

这篇关于kafka涉及微服务架构时如何实现合约测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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