-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split kafka config into consumer and producer
Signed-off-by: Davit Yeghshatyan <[email protected]>
- Loading branch information
Davit Yeghshatyan
committed
Jul 23, 2018
1 parent
4039f65
commit d0a7e7e
Showing
12 changed files
with
115 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) 2018 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package consumer | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/bsm/sarama-cluster" | ||
) | ||
|
||
// Consumer is an interface to features of Sarama that are necessary for the consumer | ||
type Consumer interface { | ||
Partitions() <-chan cluster.PartitionConsumer | ||
MarkPartitionOffset(topic string, partition int32, offset int64, metadata string) | ||
io.Closer | ||
} | ||
|
||
// Builder builds a new kafka consumer | ||
type Builder interface { | ||
NewConsumer() (Consumer, error) | ||
} | ||
|
||
// Configuration describes the configuration properties needed to create a Kafka consumer | ||
type Configuration struct { | ||
Brokers []string | ||
Topic string | ||
GroupID string | ||
Consumer | ||
} | ||
|
||
// NewConsumer creates a new kafka consumer | ||
func (c *Configuration) NewConsumer() (Consumer, error) { | ||
saramaConfig := cluster.NewConfig() | ||
saramaConfig.Group.Mode = cluster.ConsumerModePartitions | ||
return cluster.NewConsumer(c.Brokers, c.GroupID, []string{c.Topic}, saramaConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requires connection to Kafka |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2018 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package producer | ||
|
||
import ( | ||
"github.com/Shopify/sarama" | ||
) | ||
|
||
// Builder builds a new kafka producer | ||
type Builder interface { | ||
NewProducer() (sarama.AsyncProducer, error) | ||
} | ||
|
||
// Configuration describes the configuration properties needed to create a Kafka producer | ||
type Configuration struct { | ||
Brokers []string | ||
} | ||
|
||
// NewProducer creates a new asynchronous kafka producer | ||
func (c *Configuration) NewProducer() (sarama.AsyncProducer, error) { | ||
saramaConfig := sarama.NewConfig() | ||
saramaConfig.Producer.Return.Successes = true | ||
return sarama.NewAsyncProducer(c.Brokers, saramaConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters