Skip to content

Commit

Permalink
print out more information of the message
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed May 15, 2019
1 parent 63b3a46 commit d1e35b6
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,59 @@ import (

var insecure bool

func printTitle(title string) {
fmt.Println("---------------------------------------------------------")
fmt.Println("#", title)
fmt.Println("---------------------------------------------------------")
}

func dumpAnnotations(title string, data map[interface{}]interface{}) {
if len(data) > 0 {
printTitle(title)
for k, v := range data {
fmt.Printf("%s => %s", k, v)
fmt.Println()
}
}
}

func dumpProperties(title string, data map[string]interface{}) {
if len(data) > 0 {
printTitle(title)
for k, v := range data {
fmt.Printf("%s => %s", k, v)
fmt.Println()
}
}
}

func dumpMessageProperties(p *amqp.MessageProperties) {
printTitle("Properties")

fmt.Println("Content Encoding:", p.ContentEncoding)
fmt.Println("Content Type:", p.ContentType)
fmt.Println("Message ID:", p.MessageID)
fmt.Println("Subject:", p.Subject)
fmt.Println("To:", p.To)

}

func dumpMessage(msg *amqp.Message) {

dumpAnnotations("Annotations", msg.Annotations)
dumpAnnotations("Delivery annotations", msg.DeliveryAnnotations)

dumpMessageProperties(msg.Properties)
dumpProperties("Application Properties", msg.ApplicationProperties)

fmt.Println("---------------------------------------------------------")
fmt.Println("Payload")
fmt.Println("---------------------------------------------------------")
fmt.Printf("%s", msg.GetData())
fmt.Println()
fmt.Println("=========================================================")
}

func consume(messageType string, uri string, tenant string) error {

fmt.Printf("Consuming %s from %s ...", messageType, uri)
Expand Down Expand Up @@ -71,6 +124,7 @@ func consume(messageType string, uri string, tenant string) error {
}()

fmt.Printf("Consumer running, press Ctrl+C to stop...")
fmt.Println()

for {
// Receive next message
Expand All @@ -84,7 +138,7 @@ func consume(messageType string, uri string, tenant string) error {
return nil
}

fmt.Printf("Message received: %s\n", msg.GetData())
dumpMessage(msg)
}
}

Expand Down

0 comments on commit d1e35b6

Please sign in to comment.