Skip to content
Open
Changes from 1 commit
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
91 changes: 61 additions & 30 deletions pkg/outputs/kafka_output/kafka_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,33 @@ type dynConfig struct {

// config //
type config struct {
Address string `mapstructure:"address,omitempty"`
Topic string `mapstructure:"topic,omitempty"`
TopicPrefix string `mapstructure:"topic-prefix,omitempty"`
Name string `mapstructure:"name,omitempty"`
SASL *types.SASL `mapstructure:"sasl,omitempty"`
TLS *types.TLSConfig `mapstructure:"tls,omitempty"`
MaxRetry int `mapstructure:"max-retry,omitempty"`
Timeout time.Duration `mapstructure:"timeout,omitempty"`
RecoveryWaitTime time.Duration `mapstructure:"recovery-wait-time,omitempty"`
FlushFrequency time.Duration `mapstructure:"flush-frequency,omitempty"`
SyncProducer bool `mapstructure:"sync-producer,omitempty"`
RequiredAcks string `mapstructure:"required-acks,omitempty"`
Format string `mapstructure:"format,omitempty"`
InsertKey bool `mapstructure:"insert-key,omitempty"`
AddTarget string `mapstructure:"add-target,omitempty"`
TargetTemplate string `mapstructure:"target-template,omitempty"`
MsgTemplate string `mapstructure:"msg-template,omitempty"`
SplitEvents bool `mapstructure:"split-events,omitempty"`
NumWorkers int `mapstructure:"num-workers,omitempty"`
CompressionCodec string `mapstructure:"compression-codec,omitempty"`
KafkaVersion string `mapstructure:"kafka-version,omitempty"`
Debug bool `mapstructure:"debug,omitempty"`
BufferSize int `mapstructure:"buffer-size,omitempty"`
OverrideTimestamps bool `mapstructure:"override-timestamps,omitempty"`
EnableMetrics bool `mapstructure:"enable-metrics,omitempty"`
EventProcessors []string `mapstructure:"event-processors,omitempty"`
Address string `mapstructure:"address,omitempty"`
Topic string `mapstructure:"topic,omitempty"`
TopicPrefix string `mapstructure:"topic-prefix,omitempty"`
Name string `mapstructure:"name,omitempty"`
SASL *types.SASL `mapstructure:"sasl,omitempty"`
TLS *types.TLSConfig `mapstructure:"tls,omitempty"`
MaxRetry int `mapstructure:"max-retry,omitempty"`
Timeout time.Duration `mapstructure:"timeout,omitempty"`
RecoveryWaitTime time.Duration `mapstructure:"recovery-wait-time,omitempty"`
FlushFrequency time.Duration `mapstructure:"flush-frequency,omitempty"`
SyncProducer bool `mapstructure:"sync-producer,omitempty"`
RequiredAcks string `mapstructure:"required-acks,omitempty"`
Format string `mapstructure:"format,omitempty"`
InsertKey bool `mapstructure:"insert-key,omitempty"`
AddTarget string `mapstructure:"add-target,omitempty"`
TargetTemplate string `mapstructure:"target-template,omitempty"`
MsgTemplate string `mapstructure:"msg-template,omitempty"`
SplitEvents bool `mapstructure:"split-events,omitempty"`
NumWorkers int `mapstructure:"num-workers,omitempty"`
CompressionCodec string `mapstructure:"compression-codec,omitempty"`
KafkaVersion string `mapstructure:"kafka-version,omitempty"`
Debug bool `mapstructure:"debug,omitempty"`
BufferSize int `mapstructure:"buffer-size,omitempty"`
OverrideTimestamps bool `mapstructure:"override-timestamps,omitempty"`
EnableMetrics bool `mapstructure:"enable-metrics,omitempty"`
EventProcessors []string `mapstructure:"event-processors,omitempty"`
AddHeaders map[string]string `mapstructure:"add-headers,omitempty"`
}

func (c *config) LogValue() slog.Value {
Expand Down Expand Up @@ -612,10 +613,25 @@ CRPROD:
}
}

var headers []sarama.RecordHeader
for k, v := range cfg.AddHeaders {
headers = append(headers, sarama.RecordHeader{
Key: []byte(k),
Value: []byte(v),
})
}

headers = append(headers, sarama.RecordHeader{
Key: []byte("sub"),
Value: []byte(m.GetMeta()["subscription-name"]),
})

topic := k.selectTopic(m.GetMeta())
msg := &sarama.ProducerMessage{
Topic: topic,
Value: sarama.ByteEncoder(b),
Topic: topic,
Value: sarama.ByteEncoder(b),
Headers: headers,
Timestamp: time.Now(),
}
if cfg.InsertKey {
msg.Key = sarama.ByteEncoder(k.partitionKey(m.GetMeta()))
Expand Down Expand Up @@ -688,10 +704,25 @@ CRPROD:
}
}

var headers []sarama.RecordHeader
for k, v := range cfg.AddHeaders {
headers = append(headers, sarama.RecordHeader{
Key: []byte(k),
Value: []byte(v),
})
}
Comment thread
senthilsam marked this conversation as resolved.
Outdated

headers = append(headers, sarama.RecordHeader{
Key: []byte("sub"),
Value: []byte(m.GetMeta()["subscription-name"]),
})
Comment thread
senthilsam marked this conversation as resolved.
Outdated

topic := k.selectTopic(m.GetMeta())
msg := &sarama.ProducerMessage{
Topic: topic,
Value: sarama.ByteEncoder(b),
Topic: topic,
Value: sarama.ByteEncoder(b),
Headers: headers,
Timestamp: time.Now(),
Comment thread
senthilsam marked this conversation as resolved.
Outdated
}
if cfg.InsertKey {
msg.Key = sarama.ByteEncoder(k.partitionKey(m.GetMeta()))
Expand Down
Loading