Skip to content

Commit

Permalink
ZBIO-120: producer image and producer yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
harishagrawal committed Mar 9, 2020
1 parent 4309450 commit ca31e8a
Show file tree
Hide file tree
Showing 12 changed files with 587 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pub-sub/consumer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:alpine
#RUN apk add git g++ gcc
#RUN go get -v github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc \
# github.com/opentracing/opentracing-go
#RUN apk del git

# ADD zbclient /zbclient
# WORKDIR /zbclient
# #ADD . /go/src/github.com/ZB-io/zbio/client
# #WORKDIR /go/src/github.com/ZB-io/zbio/client

# ENTRYPOINT ./zbclient.sh
# CMD [default]

63 changes: 63 additions & 0 deletions pub-sub/consumer/consumer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"fmt"
"log"

"github.com/ZB-io/zbio/client"
)

var (
zbCli *client.Client2020-03-05T10:21:32.623+0530 info client/client.go:323 Requested NewMessage data: [topic:"test-topic-1" data:"Message number 56 " ]

)

func init() {

cfg := client.Config{

Name: "TestProducer",
ServiceEndPoint: "zbio-service:50002",
}
cli, err := client.New(cfg)

if err != nil {
fmt.Println("Failed to get client, err=", err)
} else {
zbCli = cli
}
}

func main() {

startConsumer()

}

func startConsumer() {

topics := []string{"test-topic-1", "test-topic-2"}

msgChanMap, err := zbCli.ReadMessages("testClient", "TestClientGroup",
topics)

if err != nil {
log.Fatal("Read message failed " + err.Error())
}

go func() {
for {
select {
case msg := <-msgChanMap[topics[0]]:
fmt.Println("Message Received ", topics[0], string(msg))

case msg := <-msgChanMap[topics[1]]:
fmt.Println("Message Received ", topics[1], string(msg))

}
}
}()

select {}

}
Empty file added pub-sub/consumer/consumer.yaml
Empty file.
5 changes: 5 additions & 0 deletions pub-sub/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/ZB-io/zbio-example/pub-sub

go 1.13

require github.com/ZB-io/zbio v0.0.2
352 changes: 352 additions & 0 deletions pub-sub/go.sum

Large diffs are not rendered by default.

Binary file added pub-sub/producer/bin/producer
Binary file not shown.
21 changes: 21 additions & 0 deletions pub-sub/producer/bin/server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDbjCCAlYCCQDi7l8EzZo2hDANBgkqhkiG9w0BAQsFADB5MQswCQYDVQQGEwJV
UzELMAkGA1UECAwCQ0ExETAPBgNVBAcMCFNhbiBKb3NlMQ4wDAYDVQQKDAVaYi5p
bzENMAsGA1UECwwEWmJpbzEOMAwGA1UEAwwFemIuaW8xGzAZBgkqhkiG9w0BCQEW
DHN1ZGhpckB6Yi5pbzAeFw0yMDAxMTQxMjM2MTVaFw0zMDAxMTExMjM2MTVaMHkx
CzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTERMA8GA1UEBwwIU2FuIEpvc2UxDjAM
BgNVBAoMBVpiLmlvMQ0wCwYDVQQLDARaYmlvMQ4wDAYDVQQDDAV6Yi5pbzEbMBkG
CSqGSIb3DQEJARYMc3VkaGlyQHpiLmlvMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
MIIBCgKCAQEAyCRRY0H09sSGFckgOrlZCABVWYiIz9XM0PLP7lL+ip+mF2KLc438
a4S/y7dsPUswIoUyfWXojNJ/VhmiynyuMVHDgeDYuX+rPXoeIXC07xd9VDZ0iG6x
lxhWMfowvkfuhTH48gYjlMy7mQhcCtsCcSMSYCx3pCYQtB7xNnlJ3cchhZAtqQhM
SBIKsQcVuF7yWghWXKitu5cO3dFKPphfFXN2vAaE1UqexIYVmByeSXdScjzU91PO
F/S1uVKg7dWIaP+lPmyXUh9uo7msZgS8JnTy8MDm47ksUwnSufUCbzId7x1sIz4x
hgzExPbZQkcttAKuuG1NAzfbf6sj5szozwIDAQABMA0GCSqGSIb3DQEBCwUAA4IB
AQAD48UpBOg7mzmIw7X11us7pGdu6gAKFk8R/vTfp3YyX8zCYL5T/RaGpH+buJfI
DiJi4RkXRSoslD1hQGK/GVfVgTtOIxJT2xd0ddIt2lcfxaPR83LpACuxAWtzWWis
LEft+yBggoaeakxvfbud8gvpP8Dme76CEU+sEoCI8tmDLHljK6zJTwqyd+jqC1T/
M0gOlbmkx3621toKzhUdj/n9jf+2f5AaGEEXaGCpC520R82/xd81hsMEdzLaRUwv
SbM5SL8bcgSxOow0ijUB9zPNaXt7CWcSEfvqkcLmB+o8+cJYi0+ZITAgELRbi5Z9
AWa8bDiglEZ9wPIRDe6MDWx3
-----END CERTIFICATE-----
9 changes: 9 additions & 0 deletions pub-sub/producer/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golang:alpine
MAINTAINER VIVEK K B <kbvivek@zb.io>
LABEL Description="This image is used to start producer " Vendor="Zettabytes" Version="1.0"

# ADD producer binary location
ADD bin /producer
WORKDIR /producer
ENV SERVER_CRT=/producer/server.crt
ENTRYPOINT ["./producer"]
12 changes: 12 additions & 0 deletions pub-sub/producer/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
all:
export GOPRIVATE="github.com/ZB-io/*"
GOOS=linux GOARCH=amd64 go build -o bin/producer .
cp ../../security/cert/server.crt bin/
ifdef NODOCKER
echo "DO NOT BUILD IMAGE"
else
docker build -f docker/Dockerfile -t zbio-example/producer:v1 .
endif

clean:
rm -f bin/*
77 changes: 77 additions & 0 deletions pub-sub/producer/producer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"fmt"
"log"
"time"

"github.com/ZB-io/zbio/client"
)

var (
zbCli *client.Client
)

func init() {

cfg := client.Config{

Name: "TestProducer",
ServiceEndPoint: "zbio-service:50002",
}
cli, err := client.New(cfg)

if err != nil {
fmt.Println("Failed to get client, err=", err)
} else {
zbCli = cli
}
}

func CreateTopics() {
var topic string
var topics []string

for i := 1; i < 5; i++ {
topic = fmt.Sprintf("test-topic-%d", i)
log.Printf("Topic Name: %v", topic)
topics = append(topics, topic)
}

ok, err := zbCli.CreateTopics(topics, "", 3, 1, 100000)
if !ok {
fmt.Errorf("Unable to create Topics due to error: %v", err)
}
}

func SendNewMessage() {
messages := []client.Message{
client.Message{
TopicName: "test-topic-1",
HintPartition: "",
Data: []byte("Message number 0"),
},
}

for i := 0; i < 1000; i++ {
messages[0].Data = []byte(fmt.Sprintf("Message number %d ", i))
response, err := zbCli.NewMessage(messages)
if err != nil {
log.Fatalf("NewMessage failed with error: %v", err)
}
log.Printf("NewMessage Response: %v", response)

time.Sleep(1 * time.Second)
}
}

func startProducer() {
CreateTopics()
SendNewMessage()
}

func main() {

startProducer()

}
13 changes: 13 additions & 0 deletions pub-sub/producer/producer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: Pod
apiVersion: v1
metadata:
name: zbio-example-producer
labels:
app: zbio-example-producer
spec:
containers:
- name: zbio-example-producer
image: zbio-example/producer:v1
imagePullPolicy: Never
restartPolicy: OnFailure
terminationGracePeriodSeconds: 0
21 changes: 21 additions & 0 deletions security/cert/server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDbjCCAlYCCQDi7l8EzZo2hDANBgkqhkiG9w0BAQsFADB5MQswCQYDVQQGEwJV
UzELMAkGA1UECAwCQ0ExETAPBgNVBAcMCFNhbiBKb3NlMQ4wDAYDVQQKDAVaYi5p
bzENMAsGA1UECwwEWmJpbzEOMAwGA1UEAwwFemIuaW8xGzAZBgkqhkiG9w0BCQEW
DHN1ZGhpckB6Yi5pbzAeFw0yMDAxMTQxMjM2MTVaFw0zMDAxMTExMjM2MTVaMHkx
CzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTERMA8GA1UEBwwIU2FuIEpvc2UxDjAM
BgNVBAoMBVpiLmlvMQ0wCwYDVQQLDARaYmlvMQ4wDAYDVQQDDAV6Yi5pbzEbMBkG
CSqGSIb3DQEJARYMc3VkaGlyQHpiLml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