feature/pubsub #7

Merged
mats merged 67 commits from feature/pubsub into main 2025-11-28 17:45:22 +01:00
Showing only changes of commit 82650bd3dd - Show all commits

View File

@@ -43,9 +43,10 @@ var (
type PoolServer struct {
actor.GrainPool[*cart.CartGrain]
pod_name string
klarnaClient *KlarnaClient
inventoryService inventory.InventoryService
pod_name string
klarnaClient *KlarnaClient
inventoryService inventory.InventoryService
inventoryListener *inventory.InventoryChangeListener
}
func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarnaClient *KlarnaClient, inventoryService inventory.InventoryService, inventoryRedisClient *redis.Client) *PoolServer {
@@ -55,7 +56,7 @@ func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarn
klarnaClient: klarnaClient,
inventoryService: inventoryService,
}
inventory.NewInventoryChangeListener(inventoryRedisClient, context.Background(), func(changes []inventory.InventoryChange) {
listener := inventory.NewInventoryChangeListener(inventoryRedisClient, context.Background(), func(changes []inventory.InventoryChange) {
for _, change := range changes {
srv.GrainPool.GetPubSub().Publish(actor.Event{
Topic: fmt.Sprintf("inventory:%s", change.SKU),
@@ -63,6 +64,8 @@ func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarn
})
}
})
srv.inventoryListener = listener
go listener.Start()
return srv
}