你应该在一个微服务的不同线程中有多个 Kafka 侦听器 运行 吗?
Should you have multiple Kafka listeners running in seperate threads in one microservice?
抱歉这个宽泛的问题。
试图了解我是否应该在单个微服务、多个线程上有多个侦听器 运行,或者每个微服务有一个侦听器。
关于值得一读的文章,有这方面的资源吗?
(上下文的用例是消息被获取、转换并通过 REST 发送到另一个服务,在 Python 中完成)。
正如 Kafka 文档所说 multithreaded
The Kafka consumer is NOT thread-safe. All network I/O happens in the thread of the application making the call. It is the responsibility of the user to ensure that multi-threaded access is properly synchronized. Un-synchronized access will result in ConcurrentModificationException.
正如 confluent 博客对 kafka-consumer-multi-threaded-messaging
的解释
When implementing a multi-threaded consumer architecture, it is important to note that the Kafka consumer is not thread safe. Multi-threaded access must be properly synchronized, which can be tricky. This is why the single-threaded model is commonly used.
所以通常使用单线程模式是安全的,风险较小。但是如果你能确保同步和并发行为,那么你可以使用多线程模式。
抱歉这个宽泛的问题。
试图了解我是否应该在单个微服务、多个线程上有多个侦听器 运行,或者每个微服务有一个侦听器。
关于值得一读的文章,有这方面的资源吗?
(上下文的用例是消息被获取、转换并通过 REST 发送到另一个服务,在 Python 中完成)。
正如 Kafka 文档所说 multithreaded
The Kafka consumer is NOT thread-safe. All network I/O happens in the thread of the application making the call. It is the responsibility of the user to ensure that multi-threaded access is properly synchronized. Un-synchronized access will result in ConcurrentModificationException.
正如 confluent 博客对 kafka-consumer-multi-threaded-messaging
的解释When implementing a multi-threaded consumer architecture, it is important to note that the Kafka consumer is not thread safe. Multi-threaded access must be properly synchronized, which can be tricky. This is why the single-threaded model is commonly used.
所以通常使用单线程模式是安全的,风险较小。但是如果你能确保同步和并发行为,那么你可以使用多线程模式。