This repository has been archived by the owner on Apr 28, 2023. It is now read-only.
/
gorewind.go
102 lines (90 loc) · 2.8 KB
/
gorewind.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// gorewind is an event store server written in Python that talks ZeroMQ.
// Copyright (C) 2013 Jens Rantil
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// GoRewind is an event store server written in Go that talks ZeroMQ.
package main
import (
"flag"
"log"
"os"
"os/signal"
"github.com/JensRantil/gorewind/server"
"github.com/JensRantil/gorewind/eventstore"
"github.com/syndtr/goleveldb/leveldb/storage"
zmq "github.com/alecthomas/gozmq"
)
var (
eventStorePath = flag.String("datadir", "data",
"directory path where incoming events will be stored. Created"+
" if non-existent.")
commandSocketZPath = flag.String("commandsocket",
"tcp://127.0.0.1:9002", "Command socket. Handles new eventsand"+
" queries.")
eventPublishZPath = flag.String("evpubsocket",
"tcp://127.0.0.1:9003", "ZeroMQ event publishing socket.")
inMemoryStore = flag.Bool("in-memory", false,
"Use in-memory store. Useful for automated client testing.")
)
// 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()
}