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

问题描述

我目前正在开发一个项目,我们在微服务架构中实现了kafka。如果您成功创建了mS到kafka主题交互的合同测试用例,请使用pact-jvm?

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主题中检索消息。

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,它封装了一条消息在某种机制上消耗(单向),通常是消息队列。我们的想法是测试消费者代码可以通过消费者测试消费消息,然后验证提供者是否生成了适当的消息。测试中未使用实际的消息队列。

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.

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

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:





  • Gradle Plugin
  • Maven Plugin
  • JUnit Example

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

07-15 10:42