Skip to content

Commit 3e4dfc6

Browse files
author
Daniel Jimenez
committed
Add Kafka to processor's integration tests
1 parent d58c71c commit 3e4dfc6

File tree

5 files changed

+226
-77
lines changed

5 files changed

+226
-77
lines changed

cmd/vulnerability-db-consumer/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func buildKafkaNotifier(conf *config, logger *log.Logger) (*notify.KafkaNotifier
132132
if err != nil {
133133
return nil, err
134134
}
135-
return notify.NewKafkaNotifier(&kafkaCli, logger), nil
135+
return notify.NewKafkaNotifier(kafkaCli, logger), nil
136136
}
137137

138138
func setupLogger(cfg config) *log.Logger {

pkg/asyncapi/kafka/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Client struct {
3232
// NewClient creates a new Kafka client connected to the a broker using the
3333
// given credentials and setting the mapping between all the entities and their
3434
// corresponding topics.
35-
func NewClient(user string, password string, broker string, topic string) (Client, error) {
35+
func NewClient(user string, password string, broker string, topic string) (*Client, error) {
3636
config := kafka.ConfigMap{
3737
"bootstrap.servers": broker,
3838
}
@@ -44,9 +44,9 @@ func NewClient(user string, password string, broker string, topic string) (Clien
4444
}
4545
p, err := kafka.NewProducer(&config)
4646
if err != nil {
47-
return Client{}, err
47+
return &Client{}, err
4848
}
49-
return Client{p, topic}, nil
49+
return &Client{p, topic}, nil
5050
}
5151

5252
// Push sends the payload of an entity, with the specified id, to corresponding

test/docker-compose.yml

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
version: '2'
44

55
services:
6+
# PostgreSQL
67
vulndb_test:
78
container_name: vulndb_test
89
image: postgres:11-alpine
@@ -17,3 +18,22 @@ services:
1718
- POSTGRES_USER=vulndb_test
1819
- POSTGRES_PASSWORD=vulndb_test
1920
- POSTGRES_DB=vulndb_test
21+
# Kafka
22+
zookeeper:
23+
image: confluentinc/cp-zookeeper:7.2.1
24+
environment:
25+
- ZOOKEEPER_CLIENT_PORT=2181
26+
- ZOOKEEPER_TICK_TIME=2000
27+
kafka:
28+
image: confluentinc/cp-kafka:7.2.1
29+
depends_on:
30+
- zookeeper
31+
ports:
32+
- 29092:29092
33+
environment:
34+
- KAFKA_BROKER_ID=1
35+
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
36+
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
37+
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
38+
- KAFKA_INTER_BROKER_LISTENER_NAME=PLAINTEXT
39+
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1

0 commit comments

Comments
 (0)