Skip to content

Question: Explicitly specify partition to send message to when said partition can change #416

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

Closed
ghost opened this issue Mar 18, 2020 · 2 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Mar 18, 2020

The way I understand it there are 2 ways to produce messages in kafka-go. You either use Conn to produce messages to a particular partition of a particular topic, or you use Writer to produce messages to a particular topic letting balancer to choose which partition to send message to.

So I guess if one wants to explicitly specify partition to send message to while using only one underlying connection, he should use custom balancer which always returns the same partition? Something like

type CustomBalancer struct {
	// lock may be required depending on the usage, I guess...
	Partition int
}

func (cb *CustomBalancer) Balance(_ Message, _ ...int) int {
	return cb.Partition
}

func (cb *CustomBalancer) SetPartition(partition int) {
	cb.Partition = partition
}
@ghost ghost added the enhancement label Mar 18, 2020
@achille-roussel
Copy link
Contributor

Hello @CheKhenKho.

Partitions are local to brokers in a kafka cluster, you can use one connection per broker but you cannot use a single connection per cluster.

The implementation of kafka.Writer isn't cheap in terms of connections, but we've been working on improving this for the 0.4.x releases.

@achille-roussel
Copy link
Contributor

Closing since #461 has improved connection management.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant