func StartOrderAgent(order Order) error { a := &OrderAgent{ id: ebus.Id("Order", order.OrderNo), order: order, openItems: make(map[int]bool), shippedTopic: ebus.Id("WarehouseShipped", order.OrderNo), } _, err := ebus.Register(a) if err != nil { return err } ebus.Subscribe(a, a.shippedTopic) // Emit a request for each order idem. for _, item := range order.OrderItems { a.openItems[item.ItemNo] = true ebus.Emit(item, "WarehouseItemOrdered") } return nil }
func StartWaitAgent(done chan bool) error { a := &WaitAgent{ id: ebus.Id("Wait"), done: done, deliveredTopic: "OrderDelivered", } _, err := ebus.Register(a) if err != nil { return err } ebus.Subscribe(a, a.deliveredTopic) return nil }
func StartDeliveryAgent() error { a := &DeliveryAgent{ id: ebus.Id("Delivery"), openOrders: make(map[int]bool), receivedTopic: "OrderReceived", packedTopic: "OrderPacked", } _, err := ebus.Register(a) if err != nil { return err } ebus.Subscribe(a, a.receivedTopic) ebus.Subscribe(a, a.packedTopic) return nil }
func StartManufacturerAgent() error { a := &ManufacturerAgent{ id: ebus.Id("Manufacturer"), openOrders: make(map[int]int), orderedTopic: "ManufacturerItemOrdered", manufacturedTopic: "OrderedItemsManufactured", } _, err := ebus.Register(a) if err != nil { return err } ebus.AddTicker("Manufacturing", time.Second, a.manufacturedTopic) ebus.Subscribe(a, a.orderedTopic) ebus.Subscribe(a, a.manufacturedTopic) return nil }
func StartWarehouseAgent() error { a := &WarehouseAgent{ id: ebus.Id("Warehouse"), inventory: make(map[int]int), openOrders: make(map[int]map[int]OrderItem), orderedTopic: "WarehouseItemOrdered", shippedTopic: "ManufacturingShipped", preparedTopic: "OrderItemsPrepared", } _, err := ebus.Register(a) if err != nil { return err } ebus.AddTicker("Warehouse", time.Second, a.preparedTopic) ebus.Subscribe(a, a.orderedTopic) ebus.Subscribe(a, a.shippedTopic) ebus.Subscribe(a, a.preparedTopic) return nil }