コード例 #1
0
ファイル: evstoreclient.go プロジェクト: vsysoev/goeventstore
func genDataFromGenFile(ctx context.Context, genFile *bufio.Reader, evStore evstore.Connection) {
	chanInput := make(chan string, 1)
	for {
		s, _, err := genFile.ReadLine()
		if err == io.EOF {
			log.Println("EOF")
			break
		}
		if err != nil {
			log.Panicln(err)
		}
		go genData(ctx, string(s), chanInput)
	}
	log.Println("Waiting for Ctrl-C")
Loop:
	for {
		select {
		case <-ctx.Done():
			break Loop
		case msg := <-chanInput:
			log.Println(msg)
			evStore.Committer().SubmitEvent("", "scalar", msg)
		}
	}
}
コード例 #2
0
ファイル: evstoreclient.go プロジェクト: vsysoev/goeventstore
func send2EventStore(r *bufio.Reader, evStore evstore.Connection) {
	for {
		s, _, err := r.ReadLine()
		if err == io.EOF {
			break
		}
		if err != nil {
			return
		}
		fmt.Println(string(s))
		err = evStore.Committer().SubmitEvent("", "scalar", string(s))
		if err != nil {
			log.Println(err)
		}
	}
	return
}
コード例 #3
0
func handleClientRequest(ctx context.Context, c Connector, e evstore.Connection) {
	var ev map[string]interface{}
	fromWS, toWS, doneCh := c.GetChannels()
Loop:
	for {
		select {
		case <-ctx.Done():
		case <-doneCh:
			break Loop
		case msg := <-fromWS:
			response := wsock.MessageT{"reply": "ok"}
			seqid := ""
			if val, ok := (*msg)["sequenceid"].(string); ok {
				seqid = val
			}
			tag := ""
			if val, ok := (*msg)["tag"].(string); ok {
				tag = val
			} else {
				response["reply"] = "ERROR"
				response["msg"] = "No tag"
			}
			if val, ok := (*msg)["event"].(map[string]interface{}); ok {
				ev = val
			} else {
				response["reply"] = "ERROR"
				response["msg"] = "No event"
			}
			if response["reply"] == "ok" {
				err := e.Committer().SubmitMapStringEvent(seqid, tag, ev)
				if err != nil {
					response["reply"] = "ERROR"
					response["msg"] = "Submit to eventstore failed"
				}
			}
			toWS <- &response
			break
		case <-time.After(time.Millisecond * 10):
			break
		}
	}
}
コード例 #4
0
ファイル: eventsrv.go プロジェクト: vsysoev/goeventstore
func clientHandler(ctx context.Context, c *wsock.Client, evStore evstore.Connection) {
	var (
		err error
	)
	//	state := make(ScalarState)
	log.Println("clientProcessor Client connected. ", c.Request())
	id := c.Request().FormValue("id")
	tag := c.Request().FormValue("tag")
	_, toWS, doneCh := c.GetChannels()
	if tag != "" {
		err = evStore.Listenner2().Subscribe2(tag, messageHandler)
		if err != nil {
			log.Println("Can't subscribe to evStore", err)
			return
		}
		ctx2 := context.WithValue(ctx, "toWS", toWS)
		ctx3, cancel := context.WithCancel(ctx2)
		defer cancel()
		go evStore.Listenner2().Listen(ctx3, id)
	} else {
		js := wsock.MessageT{}
		js["response"] = "ERROR: No tag to subscribe"
		toWS <- &js
	}

	log.Println("Enter main loop serving client")
Loop:
	for {
		select {
		case <-doneCh:
			log.Println("Client disconnected. Exit goroutine")
			break Loop
		}
	}
	log.Println("Exit clientProcessor")
}