This file contains hidden or 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
| package main | |
| import ( | |
| "io" | |
| "log" | |
| "golang.org/x/net/context" | |
| "google.golang.org/grpc" | |
| pb "github.com/shijuvar/go-recipes/grpc/customer" |
This file contains hidden or 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
| // Benchmark testing to measure the performance of marshaling and unmarshaling of ProtoBuf, JSON and XML | |
| package order | |
| import ( | |
| "encoding/json" | |
| "encoding/xml" | |
| "testing" | |
| "time" | |
| "github.com/golang/protobuf/proto" |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| var orderServiceUri string | |
| orderServiceUri = viper.GetString("discovery.orderservice") | |
| func main() { | |
| // Create server connection | |
| natsConnection, _ := nats.Connect(nats.DefaultURL) | |
| log.Println("Connected to " + nats.DefaultURL) | |
| natsConnection.Subscribe("Discovery.OrderService", func(m *nats.Msg) { | |
| orderServiceDiscovery := pb.ServiceDiscovery{OrderServiceUri: orderServiceUri} |
This file contains hidden or 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 ( | |
| aggregate = "Order" | |
| event = "OrderCreated" | |
| ) | |
| // publishOrderCreated publish an event via NATS server | |
| func publishOrderCreated(order *pb.Order) { | |
| // Connect to NATS server | |
| natsConnection, _ := nats.Connect(nats.DefaultURL) | |
| log.Println("Connected to " + nats.DefaultURL) |
This file contains hidden or 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{} |
This file contains hidden or 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 ( | |
| queue = "Order.OrdersCreatedQueue" | |
| subject = "Order.OrderCreated" | |
| ) | |
| func main() { | |
| // Create server connection | |
| natsConnection, _ := nats.Connect(nats.DefaultURL) | |
| log.Println("Connected to " + nats.DefaultURL) |
This file contains hidden or 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
| package main | |
| import ( | |
| "context" | |
| "log" | |
| "net" | |
| stan "github.com/nats-io/go-nats-streaming" | |
| "google.golang.org/grpc" |
This file contains hidden or 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
| ackHandler := func(ackedNuid string, err error) { | |
| if err != nil { | |
| log.Printf("Error publishing message id %s: %v\n", ackedNuid, err.Error()) | |
| } else { | |
| log.Printf("Received ACK for message id %s\n", ackedNuid) | |
| } | |
| } | |
| channel := event.Channel | |
| eventMsg := []byte(event.EventData) |
This file contains hidden or 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
| package main | |
| import ( | |
| "encoding/json" | |
| "log" | |
| "runtime" | |
| "time" | |
| stan "github.com/nats-io/go-nats-streaming" |