Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ConsumeClaimWithContext #1892

Closed
alok87 opened this issue Feb 28, 2021 · 1 comment
Closed

Support for ConsumeClaimWithContext #1892

alok87 opened this issue Feb 28, 2021 · 1 comment

Comments

@alok87
Copy link

alok87 commented Feb 28, 2021

Problem Description
// consumerGroupHandler.ConsumeClaim() is called for every topic partition
type consumerGroupHandler struct {
	ctx   context.Context
}	

func (c *consumerGroupHandler) ConsumeClaim(session sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
       // use c.ctx
}

At present ConsumeClaim function does not accept context. So the context needs to be kept in struct consumerGroupHandler.

Support for ConsumeClaimWithContext() would help.

Golang still recommends passing context to every function. golang/go#22602

Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it. The Context should be the first parameter, typically named ctx

@chanced
Copy link

chanced commented Mar 4, 2021

I replied about Session having a Context() but I read through your other thread and it seems you know that.

I think I disagree with ConsumeClaimWithContext as it obscures the fact that Context is available with ConsumeClaim. You can always introduce your own method:

func (c *consumerGroupHandler) ConsumeClaim(session sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
    return c.ConsumeClaimWithContext(session.Context(), session, claim)
}
func (c *consumerGroupHandler) ConsumeClaimWithContext(ctx context.Context, session sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
       // use ctx
}

I realize that the context being the first param would have been idiomatic but changing the interface now would be a breaking change.

@alok87 alok87 closed this as completed Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants