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"
|
2020-10-12 12:14:51 +03:00
|
|
|
"github.com/unistack-org/micro/v3/client"
|
2020-08-27 11:39:36 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
DefaultReaderConfig = kafka.WriterConfig{}
|
|
|
|
DefaultWriterConfig = kafka.ReaderConfig{}
|
|
|
|
)
|
|
|
|
|
|
|
|
type readerConfigKey struct{}
|
|
|
|
type writerConfigKey struct{}
|
|
|
|
|
|
|
|
func ReaderConfig(c kafka.ReaderConfig) broker.Option {
|
2020-09-22 13:22:12 +03:00
|
|
|
return broker.SetOption(readerConfigKey{}, c)
|
2020-08-27 11:39:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func WriterConfig(c kafka.WriterConfig) broker.Option {
|
2020-09-22 13:22:12 +03:00
|
|
|
return broker.SetOption(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
|
|
|
}
|
2020-10-10 00:55:43 +03:00
|
|
|
|
|
|
|
type publishKey struct{}
|
|
|
|
|
|
|
|
func PublishKey(key []byte) broker.PublishOption {
|
|
|
|
return broker.SetPublishOption(publishKey{}, key)
|
|
|
|
}
|
2020-10-12 12:14:51 +03:00
|
|
|
|
|
|
|
func ClientPublishKey(key []byte) client.PublishOption {
|
|
|
|
return client.SetPublishOption(publishKey{}, key)
|
|
|
|
}
|