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 init() { | |
grpcLog = grpclog.NewLoggerV2(os.Stdout, os.Stderr, os.Stderr) | |
grpclog.SetLoggerV2(grpcLog) | |
} | |
func main() { | |
lis, err := net.Listen("tcp", port) | |
if err != nil { | |
grpcLog.Fatalf("failed to listen: %v", err) | |
} | |
// Creates a new gRPC server with UnaryInterceptor |
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
// Authorization unary interceptor function to handle authorize per RPC call | |
func serverInterceptor(ctx context.Context, | |
req interface{}, | |
info *grpc.UnaryServerInfo, | |
handler grpc.UnaryHandler) (interface{}, error) { | |
start := time.Now() | |
// Skip authorize when GetJWT is requested | |
if info.FullMethod != "/proto.EventStoreService/GetJWT" { | |
if err := authorize(ctx); err != nil { | |
return nil, err |
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" | |
stan "github.com/nats-io/go-nats-streaming" | |
"github.com/shijuvar/gokit/examples/nats-streaming/pb" |
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" |
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 ( | |
"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
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
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 ( | |
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
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} |
NewerOlder