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

[issue 443]add ctx for producer interceptor #505

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pulsar/producer_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package pulsar

import "context"

type ProducerInterceptor interface {
// BeforeSend This is called before send the message to the brokers. This method is allowed to modify the
BeforeSend(producer Producer, message *ProducerMessage)
BeforeSend(ctx context.Context, producer Producer, message *ProducerMessage)

// OnSendAcknowledgement This method is called when the message sent to the broker has been acknowledged,
// or when sending the message fails.
Expand All @@ -28,9 +30,9 @@ type ProducerInterceptor interface {

type ProducerInterceptors []ProducerInterceptor

func (x ProducerInterceptors) BeforeSend(producer Producer, message *ProducerMessage) {
func (x ProducerInterceptors) BeforeSend(ctx context.Context, producer Producer, message *ProducerMessage) {
for i := range x {
x[i].BeforeSend(producer, message)
x[i].BeforeSend(ctx, producer, message)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pulsar/producer_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ func (p *partitionProducer) internalSendAsync(ctx context.Context, msg *Producer
flushImmediately: flushImmediately,
publishTime: time.Now(),
}
p.options.Interceptors.BeforeSend(p, msg)
p.options.Interceptors.BeforeSend(ctx, p, msg)

if p.options.DisableBlockIfQueueFull {
if !p.publishSemaphore.TryAcquire() {
Expand Down
5 changes: 3 additions & 2 deletions pulsar/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,8 @@ func TestSendTimeout(t *testing.T) {

type noopProduceInterceptor struct{}

func (noopProduceInterceptor) BeforeSend(producer Producer, message *ProducerMessage) {}
func (noopProduceInterceptor) BeforeSend(ctx context.Context, producer Producer, message *ProducerMessage) {
}

func (noopProduceInterceptor) OnSendAcknowledgement(producer Producer, message *ProducerMessage, msgID MessageID) {
}
Expand All @@ -943,7 +944,7 @@ type metricProduceInterceptor struct {
ackn int
}

func (x *metricProduceInterceptor) BeforeSend(producer Producer, message *ProducerMessage) {
func (x *metricProduceInterceptor) BeforeSend(ctx context.Context, producer Producer, message *ProducerMessage) {
x.sendn++
}

Expand Down