Skip to content

Instantly share code, notes, and snippets.

@shijuvar
Last active April 10, 2017 16:12
Show Gist options
  • Select an option

  • Save shijuvar/7f34b22904476ca9cae856f36e8f24b6 to your computer and use it in GitHub Desktop.

Select an option

Save shijuvar/7f34b22904476ca9cae856f36e8f24b6 to your computer and use it in GitHub Desktop.
NATS Request-Reply Request
func main() {
// Create NATS server connection
natsConnection, _ := nats.Connect(nats.DefaultURL)
log.Println("Connected to " + nats.DefaultURL)
msg, err := natsConnection.Request("Discovery.OrderService", nil, 1000*time.Millisecond)
if err == nil && msg != nil {
orderServiceDiscovery := pb.ServiceDiscovery{}
err := proto.Unmarshal(msg.Data, &orderServiceDiscovery)
if err != nil {
log.Fatalf("Error on unmarshal: %v", err)
}
address := orderServiceDiscovery.OrderServiceUri
log.Println("OrderService endpoint found at:", address)
//Set up a connection to the gRPC server.
conn, err := grpc.Dial(address, grpc.WithInsecure())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment