refactored code to breakdown init function, moved schema_util outside producer module, renamed files
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
metrics "com.navi.medici.janus/instrumentation"
|
||||
producer_module "com.navi.medici.janus/producer"
|
||||
"com.navi.medici.janus/schema"
|
||||
|
||||
metrics "com.navi.medici.janus/instrumentation"
|
||||
producer_module "com.navi.medici.janus/producer"
|
||||
// "log"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
// "log"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/Shopify/sarama"
|
||||
"github.com/Shopify/sarama"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -19,25 +19,24 @@ var (
|
||||
)
|
||||
|
||||
type RequestObject struct {
|
||||
Body []byte
|
||||
Header http.Header
|
||||
Body []byte
|
||||
Header http.Header
|
||||
}
|
||||
|
||||
func ProcessProtobufRequestChannel(topic string) {
|
||||
for {
|
||||
request := <- ProtobufRequestChannel
|
||||
request := <-ProtobufRequestChannel
|
||||
ClickstreamProtobufEventHandler(*request, topic)
|
||||
}
|
||||
}
|
||||
|
||||
func ProcessJsonRequestChannel(topic string) {
|
||||
for {
|
||||
request := <- JsonRequestChannel
|
||||
request := <-JsonRequestChannel
|
||||
ClickstreamJsonEventHandler(*request, topic)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func ClickstreamProtobufEventHandler(request RequestObject, topic string) {
|
||||
|
||||
messageBytes := request.Body
|
||||
@@ -54,7 +53,7 @@ func ClickstreamProtobufEventHandler(request RequestObject, topic string) {
|
||||
|
||||
// add schemaID]
|
||||
schemaIDBytes := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(schemaIDBytes, uint32(producer_module.SchemaVersionMap[topic]))
|
||||
binary.BigEndian.PutUint32(schemaIDBytes, uint32(schema.SchemaVersionMap[topic]))
|
||||
recordValue = append(recordValue, schemaIDBytes...)
|
||||
|
||||
// add [messageIndex]
|
||||
@@ -79,7 +78,7 @@ func ClickstreamJsonEventHandler(request RequestObject, topic string) {
|
||||
//getting the client which has sent this event
|
||||
var result map[string]interface{}
|
||||
json.Unmarshal(messageBytes, &result)
|
||||
source := result["source"].(string)
|
||||
source := result["source"].(string)
|
||||
|
||||
// to be of the format [magicByte] + [schemaID] + [messageIndex] + [value]
|
||||
recordValue := []byte{}
|
||||
@@ -89,7 +88,7 @@ func ClickstreamJsonEventHandler(request RequestObject, topic string) {
|
||||
|
||||
// // add schemaID]
|
||||
// schemaIDBytes := make([]byte, 4)
|
||||
// binary.BigEndian.PutUint32(schemaIDBytes, uint32(producer_module.SchemaVersionMap[topic]))
|
||||
// binary.BigEndian.PutUint32(schemaIDBytes, uint32(schema.SchemaVersionMap[topic]))
|
||||
// recordValue = append(recordValue, schemaIDBytes...)
|
||||
|
||||
// Now write the bytes from the actual message...
|
||||
@@ -99,7 +98,7 @@ func ClickstreamJsonEventHandler(request RequestObject, topic string) {
|
||||
Topic: topic,
|
||||
Value: sarama.ByteEncoder(recordValue),
|
||||
}
|
||||
|
||||
|
||||
metrics.IncrementCounter("request", source)
|
||||
producer_module.WriteMessageToKafkaAsync(message, source)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user