Kafka tests (#944)

A simple test for Kafka integration which runs locally provided cluster has Kafka and Fission install has Kafka integratiom enabled (mqtrigger-kafka deployment present).
This commit is contained in:
Vishal
2018-10-22 20:07:51 +05:30
committed by GitHub
parent 619b390af3
commit e7f1d4564a
12 changed files with 159 additions and 121 deletions
+26
View File
@@ -0,0 +1,26 @@
hash: 1c2fb68841e4a62048d54923d75952578dc4812d9a5c060b031e7c4d47c4e97e
updated: 2018-10-19T14:57:56.260957841+05:30
imports:
- name: github.com/davecgh/go-spew
version: 8991bc29aa16c548c550c7ff78260e27b9ab7c73
subpackages:
- spew
- name: github.com/eapache/go-resiliency
version: ea41b0fad31007accc7f806884dcdf3da98b79ce
subpackages:
- breaker
- name: github.com/eapache/go-xerial-snappy
version: 040cc1a32f578808623071247fdbd5cc43f37f5f
- name: github.com/eapache/queue
version: 093482f3f8ce946c05bcba64badd2c82369e084d
- name: github.com/golang/snappy
version: 2e65f85255dbc3072edf28d6b5b8efc472979f5a
- name: github.com/pierrec/lz4
version: 6b9367c9ff401dbc54fabce3fb8d972e799b702d
subpackages:
- internal/xxh32
- name: github.com/rcrowley/go-metrics
version: e2704e165165ec55d062f5919b4b29494e9fa790
- name: github.com/Shopify/sarama
version: a6144ae922fd99dd0ea5046c8137acfb7fab0914
testImports: []
@@ -0,0 +1,2 @@
import:
- package: github.com/Shopify/sarama
@@ -0,0 +1,32 @@
package main
import (
"fmt"
"net/http"
sarama "github.com/Shopify/sarama"
)
// Handler posts a message to Kafka Topic
func Handler(w http.ResponseWriter, r *http.Request) {
brokers := []string{"broker.kafka.svc.cluster.local:9092"}
producerConfig := sarama.NewConfig()
producerConfig.Producer.RequiredAcks = sarama.WaitForAll
producerConfig.Producer.Retry.Max = 10
producerConfig.Producer.Return.Successes = true
producer, err := sarama.NewSyncProducer(brokers, producerConfig)
fmt.Println("Created a new producer ", producer)
if err != nil {
panic(err)
}
_, _, err = producer.SendMessage(&sarama.ProducerMessage{
Topic: "testtopic",
Value: sarama.StringEncoder("{\"name\": \"testvalue\"}"),
})
if err != nil {
w.Write([]byte(fmt.Sprintf("Failed to publish message to topic %s: %v", "testtopic", err)))
return
}
w.Write([]byte("Successfully sent to testtopic"))
}