refactor discovery
This commit is contained in:
+21
-3
@@ -27,6 +27,7 @@ import (
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/order"
|
||||
ordermcp "git.k6n.net/mats/go-cart-actor/pkg/order/mcp"
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/outbox"
|
||||
"git.k6n.net/mats/go-cart-actor/pkg/proxy"
|
||||
messages "git.k6n.net/mats/go-cart-actor/proto/order"
|
||||
"git.k6n.net/mats/platform/config"
|
||||
"git.k6n.net/mats/platform/rabbit"
|
||||
@@ -36,6 +37,9 @@ import (
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
var podIp = os.Getenv("POD_IP")
|
||||
var name = os.Getenv("POD_NAME")
|
||||
|
||||
type server struct {
|
||||
pool *actor.SimpleGrainPool[order.OrderGrain]
|
||||
applier *orderedApplier
|
||||
@@ -66,8 +70,13 @@ func main() {
|
||||
order.RegisterMutations(reg)
|
||||
storage := actor.NewDiskStorage[order.OrderGrain](dataDir, reg)
|
||||
|
||||
hostname := podIp
|
||||
if hostname == "" {
|
||||
hostname = "order-1"
|
||||
}
|
||||
|
||||
pool, err := actor.NewSimpleGrainPool(actor.GrainPoolConfig[order.OrderGrain]{
|
||||
Hostname: "order-1",
|
||||
Hostname: hostname,
|
||||
Spawn: func(ctx context.Context, id uint64) (actor.Grain[order.OrderGrain], error) {
|
||||
g := order.NewOrderGrain(id, time.Now())
|
||||
// Replay any persisted history so the resident grain is current.
|
||||
@@ -76,8 +85,8 @@ func main() {
|
||||
}
|
||||
return g, nil
|
||||
},
|
||||
SpawnHost: func(string) (actor.Host[order.OrderGrain], error) {
|
||||
return nil, fmt.Errorf("order service is single-node")
|
||||
SpawnHost: func(host string) (actor.Host[order.OrderGrain], error) {
|
||||
return proxy.NewRemoteHost[order.OrderGrain](host)
|
||||
},
|
||||
Destroy: func(actor.Grain[order.OrderGrain]) error { return nil },
|
||||
TTL: time.Hour,
|
||||
@@ -95,6 +104,15 @@ func main() {
|
||||
log.Fatalf("create pool: %v", err)
|
||||
}
|
||||
|
||||
controlPlaneConfig := actor.DefaultServerConfig()
|
||||
grpcSrv, err := actor.NewControlServer[order.OrderGrain](controlPlaneConfig, pool)
|
||||
if err != nil {
|
||||
log.Fatalf("Error starting control plane gRPC server: %v\n", err)
|
||||
}
|
||||
defer grpcSrv.GracefulStop()
|
||||
|
||||
UseDiscovery(pool)
|
||||
|
||||
applier := &orderedApplier{pool: pool, storage: storage}
|
||||
provider := selectProvider(logger)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user