✨ MQ, KV and MQ allocator
This commit is contained in:
33
pkg/internal/grpc/allocator.go
Normal file
33
pkg/internal/grpc/allocator.go
Normal file
@ -0,0 +1,33 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/internal/kv"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/internal/mq"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (v *Server) AllocMessageQueue(ctx context.Context, request *proto.AllocMqRequest) (*proto.AllocMqResponse, error) {
|
||||
if mq.Kmq == nil {
|
||||
return &proto.AllocMqResponse{IsSuccess: false}, status.Error(codes.Unavailable, "message queue wasn't configured")
|
||||
}
|
||||
|
||||
return &proto.AllocMqResponse{
|
||||
IsSuccess: true,
|
||||
Addr: viper.GetString("mq.addr"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) AllocKv(ctx context.Context, request *proto.AllocKvRequest) (*proto.AllocKvResponse, error) {
|
||||
if kv.Kv == nil {
|
||||
return &proto.AllocKvResponse{IsSuccess: false}, status.Error(codes.Unavailable, "kv wasn't configured")
|
||||
}
|
||||
|
||||
return &proto.AllocKvResponse{
|
||||
IsSuccess: true,
|
||||
Endpoints: viper.GetStringSlice("kv.endpoints"),
|
||||
}, nil
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
directory2 "git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
|
||||
"net"
|
||||
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
@ -17,6 +17,7 @@ import (
|
||||
type Server struct {
|
||||
proto.UnimplementedDatabaseServiceServer
|
||||
proto.UnimplementedStreamServiceServer
|
||||
proto.UnimplementedAllocatorServiceServer
|
||||
health.UnimplementedHealthServer
|
||||
|
||||
srv *grpc.Server
|
||||
@ -27,10 +28,11 @@ func NewServer() *Server {
|
||||
srv: grpc.NewServer(),
|
||||
}
|
||||
|
||||
proto.RegisterDirectoryServiceServer(server.srv, &directory2.ServiceRpcServer{})
|
||||
proto.RegisterCommandProviderServer(server.srv, &directory2.CommandRpcServer{})
|
||||
proto.RegisterDirectoryServiceServer(server.srv, &directory.ServiceRpcServer{})
|
||||
proto.RegisterCommandProviderServer(server.srv, &directory.CommandRpcServer{})
|
||||
proto.RegisterDatabaseServiceServer(server.srv, server)
|
||||
proto.RegisterStreamServiceServer(server.srv, server)
|
||||
proto.RegisterAllocatorServiceServer(server.srv, server)
|
||||
health.RegisterHealthServer(server.srv, server)
|
||||
|
||||
reflection.Register(server.srv)
|
||||
|
Reference in New Issue
Block a user