Last active
April 11, 2017 04:20
-
-
Save shijuvar/547e15e883983a3b12dc6b07e847d413 to your computer and use it in GitHub Desktop.
Subscriber Client of NATS Publish-Subscribe messaging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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