-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumer_test.go
48 lines (41 loc) · 1.16 KB
/
consumer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"confluent-go/model"
"encoding/json"
"github.com/confluentinc/confluent-kafka-go/kafka"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"testing"
)
func TestProvider(t *testing.T) {
var producer *kafka.Producer
var err error
producer, err = kafka.NewProducer(&kafka.ConfigMap{
"bootstrap.servers": viper.Get("BOOTSTRAP_SERVERS_CONFLUENT"),
"group.id": viper.Get("GROUP_ID"),
"security.protocol": viper.Get("SECURITY_PROTOCOL"),
"sasl.mechanisms": viper.Get("SASL_MECHANISM"),
"sasl.username": viper.Get("SASL_USERNAME"),
"sasl.password": viper.Get("SASL_PASSWORD"),
})
require.Nil(t, err)
topicName := "topic_0"
testOrder, err := json.Marshal(model.Order{
Type: "order",
Message: model.Message{
ID: "1234",
Total: 123.4,
Currency: "TRY",
CustomerID: "4321",
},
})
err = producer.Produce(&kafka.Message{
TopicPartition: kafka.TopicPartition{Topic: &topicName,
Partition: kafka.PartitionAny},
Value: testOrder}, nil)
require.Nil(t, err)
e := <-producer.Events()
message := e.(*kafka.Message)
require.Nil(t, message.TopicPartition.Error)
producer.Close()
}