Esempio n. 1
0
func setupInMemoryeventstore() *eventstore.EventStore {
	stor := &storage.MemStorage{}
	es, err := eventstore.New(stor)
	if err != nil {
		panic(err)
	}
	return es
}
Esempio n. 2
0
// Main method. Will panic if things are so bad that the application
// will not start.
func main() {
	flag.Parse()

	log.Println("Event store to use:", *eventStorePath)
	log.Println("Command socket path:", *commandSocketZPath)
	log.Println("Event publishing socket path:", *eventPublishZPath)
	log.Println()

	var stor storage.Storage
	if *inMemoryStore {
		log.Println("!!! WARNING: Using in-memory store.")
		log.Println("!!! Events will not be persisted.")
		log.Println()
		stor = &storage.MemStorage{}
	} else {
		stor, err := storage.OpenFile(*eventStorePath)
		if err != nil {
			log.Panicln("could not create DB storage")
		}
		defer stor.Close()
	}

	estore, err := eventstore.New(stor)
	if err != nil {
		log.Panicln(os.Stderr, "could not create event store")
	}

	context, err := zmq.NewContext()
	if err != nil {
		log.Panicln(err)
	}

	initParams := server.InitParams{
		Store:              estore,
		CommandSocketZPath: commandSocketZPath,
		EvPubSocketZPath:   eventPublishZPath,
		ZMQContext:         context,
	}
	serv, err := server.New(&initParams)
	if err != nil {
		panic(err.Error())
	}

	sigchan := make(chan os.Signal, 5)
	serverStopper := func() {
		sig := <-sigchan
		if sig == os.Interrupt {
			serv.Stop()
		}
	}
	go serverStopper()
	signal.Notify(sigchan)

	serv.Start()
	serv.Wait()
}