Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
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
}
Ejemplo n.º 4
0
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
}
Ejemplo n.º 5
0
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
}