Giter Club home page Giter Club logo

Comments (6)

colinrs avatar colinrs commented on September 28, 2024

我看了代码,认为也会是这样,会导致丢消息和重复消费

from go-queue.

dinofei avatar dinofei commented on September 28, 2024

感谢对kafka-go进行服务化封装,的确用起来更简单了!

我对消费代码有个疑惑,望解答:

for i := 0; i < q.c.Processors; i++ {
		q.consumerRoutines.Run(func() {
			for msg := range q.channel {
				if err := q.consumeOne(string(msg.Key), string(msg.Value)); err != nil {
					logx.Errorf("Error on consuming: %s, error: %v", string(msg.Value), err)
				}
				q.consumer.CommitMessages(context.Background(), msg)
			}
		})
	}

多个goroutine并行提交位移是否有问题?如提前把大位移提交导致丢消息,或滞后把小位移提交导致重复消费。

不会,因为channel是无容量的,多个goroutine一起消费也只会按顺序提交

from go-queue.

1426919587 avatar 1426919587 commented on September 28, 2024

感谢对kafka-go进行服务化封装,的确用起来更简单了!
我对消费代码有个疑惑,望解答:

for i := 0; i < q.c.Processors; i++ {
		q.consumerRoutines.Run(func() {
			for msg := range q.channel {
				if err := q.consumeOne(string(msg.Key), string(msg.Value)); err != nil {
					logx.Errorf("Error on consuming: %s, error: %v", string(msg.Value), err)
				}
				q.consumer.CommitMessages(context.Background(), msg)
			}
		})
	}

多个goroutine并行提交位移是否有问题?如提前把大位移提交导致丢消息,或滞后把小位移提交导致重复消费。

不会,因为channel是无容量的,多个goroutine一起消费也只会按顺序提交

为啥,consumeOne时间不确定,即使消费者按顺序,提交也不一定按顺序

from go-queue.

dinofei avatar dinofei commented on September 28, 2024

感谢对kafka-go进行服务化封装,的确用起来更简单了!
我对消费代码有个疑惑,望解答:

for i := 0; i < q.c.Processors; i++ {
		q.consumerRoutines.Run(func() {
			for msg := range q.channel {
				if err := q.consumeOne(string(msg.Key), string(msg.Value)); err != nil {
					logx.Errorf("Error on consuming: %s, error: %v", string(msg.Value), err)
				}
				q.consumer.CommitMessages(context.Background(), msg)
			}
		})
	}

多个goroutine并行提交位移是否有问题?如提前把大位移提交导致丢消息,或滞后把小位移提交导致重复消费。

不会,因为channel是无容量的,多个goroutine一起消费也只会按顺序提交

为啥,consumeOne时间不确定,即使消费者按顺序,提交也不一定按顺序

kafka-go 会merge commit,这里面会按照message的offset排序的

from go-queue.

1426919587 avatar 1426919587 commented on September 28, 2024

感谢对kafka-go进行服务化封装,的确用起来更简单了!
我对消费代码有个疑惑,望解答:

for i := 0; i < q.c.Processors; i++ {
		q.consumerRoutines.Run(func() {
			for msg := range q.channel {
				if err := q.consumeOne(string(msg.Key), string(msg.Value)); err != nil {
					logx.Errorf("Error on consuming: %s, error: %v", string(msg.Value), err)
				}
				q.consumer.CommitMessages(context.Background(), msg)
			}
		})
	}

多个goroutine并行提交位移是否有问题?如提前把大位移提交导致丢消息,或滞后把小位移提交导致重复消费。

不会,因为channel是无容量的,多个goroutine一起消费也只会按顺序提交

为啥,consumeOne时间不确定,即使消费者按顺序,提交也不一定按顺序

kafka-go 会merge commit,这里面会按照message的offset排序的

看了一下源码,是有merge操作
func (o offsetStash) merge(commits []commit) { for _, c := range commits { offsetsByPartition, ok := o[c.topic] if !ok { offsetsByPartition = map[int]int64{} o[c.topic] = offsetsByPartition } if offset, ok := offsetsByPartition[c.partition]; !ok || c.offset > offset { offsetsByPartition[c.partition] = c.offset } } }

但是上面只要大于就更新,不是连续的啊,比如现在有offset的2,3,4个消息处理,4先提交,那2,3都没提交,万一2,3失败了,是不是也相当于他们成功,下一次获取到5的消息

from go-queue.

why2go avatar why2go commented on September 28, 2024

我也有同样的疑问,看起来是不是只能定义一个processer才能保证提交正常呀,是不是应该设计成像spring-kafka那样,每个consumer对应着一个消费线程,这样就可以保证提交不错乱了

from go-queue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.