func TestMain(m *testing.M) { // Start a temporary messaging broker ts := test.RunDefaultServer() defer ts.Shutdown() // Start OrderRouter service orSC := orderrouter.NewConfig() orSC.MessageBusURL = "nats://localhost:22222" orSC.ServiceMessageBusURL = "nats://localhost:22222" orSC.DatabaseDriver = "memstore" orSvc := orderrouter.NewOrderRouter(orSC) orSvc.Start() defer orSvc.Close() // Start Simulated FIX Sell Side sellsvc := sellsidesim.NewSellSideSimulator("") sellsvc.Start() defer sellsvc.Close() // Start a MarketConnector Service for simuilated market // 1. MC (implementation) mcSC := MCCommon.NewConfig() mcSC.MessageBusURL = "nats://localhost:22222" mcSC.DatabaseDriver = "memstore" mcSvc := MCSimulator.NewMarketConnector(mcSC) mcSvc.Start() defer mcSvc.Close() // 2. Service (heartbeating etc) sc := service.NewConfig() sc.MessageBusURL = "nats://localhost:22222" sc.ServiceName = "MC." + mcSvc.Name() svc := service.NewService(sc) svc.Start() defer svc.Stop() // Turn off logging to measure performance logger.Discard() time.Sleep(100 * time.Millisecond) // async // Connect messaging bus for this mock client if nc, err := nats.Connect("nats://localhost:22222"); err != nil { log.Fatal("error: Cannot connect to message bus") } else { msgbus = nc } code := m.Run() os.Exit(code) }
func main() { // Load configurations // Initialise Service Infrastructure sc := service.NewConfig() sc.ServiceName = "Simulator" svc := service.NewService(sc) // Initialise Component orc := common.NewConfig() orc.MessageBusURL = sc.MessageBusURL // Initialise Database Connection orc.DatabaseDriver = "memstore" orsvc := simulator.NewMarketConnector(orc) orsvc.Start() defer orsvc.Close() // Go <-svc.Start() }