nc, err := nats.Connect("demo.nats.io",
nats.ErrorHandler(func(nc *nats.Conn, s *nats.Subscription, err error) {
log.Printf("Async error in %q/%q: %v", s.Subject, s.Queue, err)
log.Printf("Async error outside subscription: %v", err)
ec, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER)
// Decoding errors will be passed to the function supplied via
// nats.ErrorHandler above, and the callback supplied here will
if _, err := ec.Subscribe("updates", func(s *stock) {
log.Printf("Stock: %s - Price: %v", s.Symbol, s.Price)
// Wait for a message to come in