2020-08-27 11:39:36 +03:00
|
|
|
package segmentio
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
kafka "github.com/segmentio/kafka-go"
|
|
|
|
"github.com/unistack-org/micro/v3/broker"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
DefaultReaderConfig = kafka.WriterConfig{}
|
|
|
|
DefaultWriterConfig = kafka.ReaderConfig{}
|
|
|
|
)
|
|
|
|
|
|
|
|
type readerConfigKey struct{}
|
|
|
|
type writerConfigKey struct{}
|
|
|
|
|
|
|
|
func ReaderConfig(c kafka.ReaderConfig) broker.Option {
|
2020-09-22 13:16:35 +03:00
|
|
|
return broker.SetBrokerOption(readerConfigKey{}, c)
|
2020-08-27 11:39:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func WriterConfig(c kafka.WriterConfig) broker.Option {
|
2020-09-22 13:16:35 +03:00
|
|
|
return broker.SetBrokerOption(writerConfigKey{}, c)
|
2020-08-27 11:39:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type subscribeContextKey struct{}
|
|
|
|
|
|
|
|
// SubscribeContext set the context for broker.SubscribeOption
|
|
|
|
func SubscribeContext(ctx context.Context) broker.SubscribeOption {
|
2020-09-22 13:16:35 +03:00
|
|
|
return broker.SetSubscribeOption(subscribeContextKey{}, ctx)
|
2020-08-27 11:39:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type subscribeReaderConfigKey struct{}
|
|
|
|
|
|
|
|
func SubscribeReaderConfig(c kafka.ReaderConfig) broker.SubscribeOption {
|
2020-09-22 13:16:35 +03:00
|
|
|
return broker.SetSubscribeOption(subscribeReaderConfigKey{}, c)
|
2020-08-27 11:39:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type subscribeWriterConfigKey struct{}
|
|
|
|
|
|
|
|
func SubscribeWriterConfig(c kafka.WriterConfig) broker.SubscribeOption {
|
2020-09-22 13:16:35 +03:00
|
|
|
return broker.SetSubscribeOption(subscribeWriterConfigKey{}, c)
|
2020-08-27 11:39:36 +03:00
|
|
|
}
|