Skip to content

Instantly share code, notes, and snippets.

@shijuvar
Last active February 22, 2020 04:08
Show Gist options
  • Save shijuvar/1a297127b33bee0220dc21f601a5906f to your computer and use it in GitHub Desktop.
Save shijuvar/1a297127b33bee0220dc21f601a5906f to your computer and use it in GitHub Desktop.
Subscriber Client with queue group, of NATS Publish-Subscribe messaging
const (
queue = "Order.OrdersCreatedQueue"
subject = "Order.OrderCreated"
)
func main() {
// Create server connection
natsConnection, _ := nats.Connect(nats.DefaultURL)
log.Println("Connected to " + nats.DefaultURL)
// Subscribe to subject
natsConnection.QueueSubscribe(subject, queue, func(msg *nats.Msg) {
eventStore := pb.EventStore{}
err := proto.Unmarshal(msg.Data, &eventStore)
if err == nil {
// Handle the message
log.Printf("Subscribed message in Worker 1: %+v\n", eventStore)
}
})
// Keep the connection alive
runtime.Goexit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment