Skip to content

Commit

Permalink
add System-Origin-ID into header msg to nativerw
Browse files Browse the repository at this point in the history
  • Loading branch information
emilolosutean committed Sep 12, 2018
1 parent bb7a552 commit c7cd461
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 19 additions & 3 deletions native/native_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ import (
"github.com/Financial-Times/service-status-go/httphandlers"
)

const nativeHashHeader = "X-Native-Hash"
const contentTypeHeader = "Content-Type"
const transactionIDHeader = "X-Request-Id"
const (
nativeHashHeader = "X-Native-Hash"
contentTypeHeader = "Content-Type"
transactionIDHeader = "X-Request-Id"
originSystemIDHeader = "Origin-System-Id"
)

// Writer provides the functionalities to write in the native store
type Writer interface {
Expand Down Expand Up @@ -76,6 +79,11 @@ func (nw *nativeWriter) WriteToCollection(msg NativeMessage, collection string)

}

if request.Header.Get(originSystemIDHeader) == "" {
logger.NewEntry(msg.TransactionID()).
WithUUID(contentUUID).
Warn("Native-save request does not have Origin-System-ID header")
}
response, err := nw.httpClient.Do(request)

if err != nil {
Expand Down Expand Up @@ -161,10 +169,18 @@ func (msg *NativeMessage) AddContentTypeHeader(hash string) {
msg.headers[contentTypeHeader] = hash
}

func (msg *NativeMessage) AddOriginSystemIDHeader(hash string) {
msg.headers[originSystemIDHeader] = hash
}

func (msg *NativeMessage) TransactionID() string {
return msg.headers[transactionIDHeader]
}

func (msg *NativeMessage) ContentType() string {
return msg.headers[contentTypeHeader]
}

func (msg *NativeMessage) OriginSystemID() string {
return msg.headers[originSystemIDHeader]
}
9 changes: 6 additions & 3 deletions queue/publication_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"
"strings"

"github.com/Financial-Times/go-logger"
"github.com/Financial-Times/kafka-client-go/kafka"
"github.com/Financial-Times/native-ingester/native"
"github.com/Financial-Times/go-logger"
)

type publicationEvent struct {
Expand Down Expand Up @@ -47,8 +47,11 @@ func (pe *publicationEvent) nativeMessage() (native.NativeMessage, error) {
if found {
msg.AddContentTypeHeader(contentType)
}

logger.NewEntry(pe.transactionID()).Infof("Constructed new NativeMessage with content-type: ", msg.ContentType())
originSystemID, found := pe.Headers["Origin-System-Id"]
if found {
msg.AddOriginSystemIDHeader(originSystemID)
}
logger.NewEntry(pe.transactionID()).Infof("Constructed new NativeMessage with content-type=%s, Origin-System-Id=%s", msg.ContentType(), msg.OriginSystemID())

return msg, nil
}
Expand Down

0 comments on commit c7cd461

Please sign in to comment.