Skip to content

Commit

Permalink
Allow multiple brokers in kafka executor
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Moura <itsme@paulomoura.com.pt>
  • Loading branch information
Espina2 committed Jan 15, 2022
1 parent 8c72a9d commit cd9417a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions builtin/bins/dkron-executor-kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"log"
"strings"

"github.com/Shopify/sarama"
"github.com/armon/circbuf"
Expand Down Expand Up @@ -65,7 +66,7 @@ func (s *Kafka) ExecuteImpl(args *dktypes.ExecuteRequest) ([]byte, error) {
config.Producer.Return.Successes = true
config.Producer.Return.Errors = true

brokers := []string{args.Config["brokerAddress"]}
brokers := strings.Split(args.Config["brokerAddress"], ",")
producer, err := sarama.NewSyncProducer(brokers, config)
if err != nil {
// Should not reach here
Expand All @@ -79,7 +80,7 @@ func (s *Kafka) ExecuteImpl(args *dktypes.ExecuteRequest) ([]byte, error) {

msg := &sarama.ProducerMessage{
Topic: args.Config["topic"],
Key: sarama.StringEncoder(args.Config["key"]),
Key: sarama.StringEncoder(args.Config["key"]),
Value: sarama.StringEncoder(args.Config["message"]),
}

Expand Down
4 changes: 2 additions & 2 deletions website/content/usage/executors/kafka.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A basic Kafka executor that produces a message on a Kafka broker.
Params

```
brokerAddress: "IP:port" of the broker
brokerAddress: Comma separated string containing "IP:port" of the brokers
key: The key of the message to produce
message: The body of the message to produce
topic: The Kafka topic for this message
Expand All @@ -22,7 +22,7 @@ Example
```json
"executor": "kafka",
"executor_config": {
"brokerAddress": "localhost:9092",
"brokerAddress": "localhost:9092,another.host:9092",
"key": "My key",
"message": "My message",
"topic": "my_topic"
Expand Down

0 comments on commit cd9417a

Please sign in to comment.