简体   繁体   English

微服务与卡夫卡消费者集团

[英]Microservice along with kafka consumer Group

We are working on a appliation in which we are using kafka. 我们正在开发一个使用kafka的应用程序。

The components of the Application are as follows, 该应用程序的组件如下,

  1. We have a microservice which gets the request's and pushes the messages to a kafka topic. 我们有一个微服务,它获取请求并将消息推送到kafka主题。 (Lets say ServiceA) (假设是ServiceA)

  2. Another microservice which consumes the messages from topics and push the data to a datastore. 另一个微服务使用主题中的消息并将数据推送到数据存储中。 (Lets say ServiceB) (比方说ServiceB)

I am clear with ServiceA part of the application but have some design confusions in the ServiceB part. 我对应用程序的ServiceA部分很清楚,但是ServiceB部分有一些设计上的困惑。

As ServiceB we are planning for REST API, 作为ServiceB,我们正在计划REST API,

  1. Is it good to bundle Consumer and controllers in a single application ? 将Consumer和Controller捆绑在一个应用程序中是否很好?
  2. For consumer i am planning to go with ConsumerGroup with multiple Consumer's to acheive more throughput. 对于消费者,我计划与具有多个消费者的ConsumerGroup一起使用,以实现更高的吞吐量。 Is there any better and efficent approach ? 有没有更好,更有效的方法?
  3. Should i take out the Consumer part of ServiceB and make it as a separate service which is independent ? 我是否应该删除ServiceB的“消费者”部分并将其作为独立的独立服务?
  4. If we are bundling it inside the ServiceB should i configure Consumer as a Listener ? 如果我们将其捆绑在ServiceB内,是否应该将Consumer配置为Listener? (We are going with spring boot for microservice) (我们将使用用于微服务的spring boot)

Thanks in Advance ! 提前致谢 !

Is it good to bundle Consumer and controllers in a single application ? 将Consumer和Controller捆绑在一个应用程序中是否很好?

Its good to bundle together by context, having a listener, wich forwards to another service to controll makes no sense in my opionion. 通过上下文将其绑定在一起,并具有一个侦听器,将其转发到另一个可控的服务,这对我而言是没有道理的。 But consider splitting up controller by different context if necessary. 但如有必要,请考虑按不同的上下文拆分控制器。 Like Martin Fowler says: start with a monolith first and than split up ( https://martinfowler.com/bliki/MonolithFirst.html ) 就像马丁·福勒(Martin Fowler)所说的那样:首先从整体开始,然后分裂( https://martinfowler.com/bliki/MonolithFirst.html

For consumer i am planning to go with ConsumerGroup with multiple Consumer's to acheive more throughput. 对于消费者,我计划与具有多个消费者的ConsumerGroup一起使用,以实现更高的吞吐量。 Is there any better and efficent approach ? 有没有更好,更有效的方法?

A consumer group makes sense if you think about scale your service B out. 如果考虑将服务B向外扩展,则消费者群体是有意义的。 If you want to have this possibility in the future, start with one instance of ServiceB inside the consumer group. 如果希望将来有这种可能性,请从使用者组中的一个ServiceB实例开始。 If you use something like kubernetes, its simple do later on deploy more instances of your service if required. 如果您使用kubernetes之类的东西,稍后在需要时部署更多服务实例将很简单。 But do not invest to much on in an eventual future. 但是不要在将来最终投入太多。 Start simple and do some monitoring, and if you figure out some bottle necks, than act. 从简单开始并进行一些监视,如果发现瓶颈,则不要采取行动。 One more thing to keep in mind, is that kafka by default keeps message for a long time (i guess 7 days by default) so if you thing in a classical message broker style you could get a lot of duplicates of your messages. 需要记住的另一件事是,默认情况下,kafka会将消息保留很长时间(我估计默认情况下为7天),因此,如果您使用经典的消息代理风格,则可能会收到很多重复消息。 Think about a update message, if somethings change, which is raised when your ServiceA starts. 考虑一下更新消息(如果发生了某些变化),该消息会在ServiceA启动时引发。 Maybe reducing the retention.ms would be an option, but take care not to loose messages. 也许可以选择减少tention.ms,但是请注意不要散乱消息。

Should i take out the Consumer part of ServiceB and make it as a separate service which is independent ? 我是否应该删除ServiceB的“消费者”部分并将其作为独立的独立服务?

No i think not. 不,我认为不是。

If we are bundling it inside the ServiceB should i configure Consumer as a Listener ? 如果我们将其捆绑在ServiceB内,是否应该将Consumer配置为Listener? (We are going with spring boot for microservice) (我们将使用用于微服务的spring boot)

Yes :-) 是的:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM