测试Kafka消费者应用程序在隔离环境中(在金丝雀部署期间)。

huangapple go评论49阅读模式
英文:

Testing kafka consumer applications in isolation (during a canary deployment)

问题

我想要能够在金丝雀部署后测试kafka消费者流程。
假设我们有一个消费kafka主题的服务。我们在生产环境中有3个实例和kafka上的3个分区。

在T0时,它们使用应用程序的V1版本。

  • 服务器 #1 (v1)
  • 服务器 #2 (v1)
  • 服务器 #3 (v1)

我开始了金丝雀部署,现在服务器 #1 上有新版本

  • 服务器 #1 (v2)
  • 服务器 #2 (v1)
  • 服务器 #3 (v1)

通过一些路由技巧,我可以确保我的API测试会访问新的实例。
但是,我无法找到一种可行的方法来测试服务器 #1 的kafka消费者流程。不能保证我发出的测试消息会被服务器 #1 消费。

我正在寻找测试策略,但是我没有找到一种好的方法,除非改变kafka拓扑或应用程序逻辑。
我想知道你对这个问题有什么看法。

英文:

I want to be able to test kafka-consumer flows after a canary deployments.
Assume we have service which consumes a kafka topic. I have 3 instances in production and 3 partitions on kafka.

At T0 they have the V1 of the application.

  • Server #1 (v1)
  • Server #2 (v1)
  • Server #3 (v1)

I start a canary deploy, and now I have the new version on Server #1

  • Server #1 (v2)
  • Server #2 (v1)
  • Server #3 (v1)

With some routing trick, I can ensure that my API tests are hitting the new instances.
But, I couldn't find a feasible way to test kafka-consumer flows for Server #1. There is no guarantee that the test message I emit, will be consumed by Server #1.

I am looking for testing strategies, but I couldn't find a good way without changing the kafka topology, or application logic.
I wonder what is your thoughts on this problem.

答案1

得分: 1

Kafka并没有这样的方法,因为v2版本可能会保持相同的消费者组ID,并且在重新平衡后无法保证它会消费以前相同的分区。

您可以使用嵌入式Kafka或测试容器来进行与Kafka客户端的集成测试,或者使用内置的MockConsumer。不要依赖外部基础设施来运行您的测试。

英文:

Kafka doesn't really have such an approach since v2 will likely maintain the same consumer group id, and there's no guarantee it'll consume the same partition as before after a rebalance

You can use embedded Kafka or test containers to do integration tests with Kafka clients, or use builtin MockConsumer. Don't depend on external infrastructure to run your tests

huangapple
  • 本文由 发表于 2023年7月23日 17:38:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76747542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定