コード例 #1
0
ファイル: client2fix_test.go プロジェクト: cyanly/gotrade
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)
}
コード例 #2
0
ファイル: main.go プロジェクト: cyanly/gotrade
func main() {

	// Load configurations

	// Initialise Service Infrastructure
	sc := service.NewConfig()
	sc.ServiceName = "OrderRouter"
	svc := service.NewService(sc)

	// Initialise OrderRouter
	orc := orderrouter.NewConfig()
	orc.ServiceMessageBusURL = sc.MessageBusURL

	// Initialise Database Connection
	orc.DatabaseDriver = "memstore"

	orsvc := orderrouter.NewOrderRouter(orc)
	orsvc.Start()
	defer orsvc.Close()

	// Go
	<-svc.Start()
}