Skip to content

Instantly share code, notes, and snippets.

@shijuvar
Last active April 11, 2017 04:20
Show Gist options
  • Save shijuvar/547e15e883983a3b12dc6b07e847d413 to your computer and use it in GitHub Desktop.
Save shijuvar/547e15e883983a3b12dc6b07e847d413 to your computer and use it in GitHub Desktop.
Subscriber Client of NATS Publish-Subscribe messaging
const subject = "Order.>"
func main() {
// Create server connection
natsConnection, _ := nats.Connect(nats.DefaultURL)
log.Println("Connected to " + nats.DefaultURL)
// Subscribe to subject
natsConnection.Subscribe(subject, func(msg *nats.Msg) {
eventStore := pb.EventStore{}
err := proto.Unmarshal(msg.Data, &eventStore)
if err == nil {
// Handle the message
log.Printf("Received message in EventStore service: %+v\n", eventStore)
store := store.EventStore{}
store.CreateEvent(&eventStore)
log.Println("Inserted event into Event Store")
}
})
// Keep the connection alive
runtime.Goexit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment