Adding some console output for the server, format length as string instead
of bytes
This commit is contained in:
		@@ -1,15 +1,15 @@
 | 
				
			|||||||
package goes
 | 
					package goes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import
 | 
				
			||||||
 | 
					(
 | 
				
			||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
	"github.com/satori/go.uuid"
 | 
						"github.com/satori/go.uuid"
 | 
				
			||||||
	"crypto/rand"
 | 
						"crypto/rand"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	_ "path"
 | 
						"path"
 | 
				
			||||||
	"reflect"
 | 
						"reflect"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
"math/big"
 | 
						"math/big"
 | 
				
			||||||
	"path"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var tempDir string
 | 
					var tempDir string
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,6 @@ import (
 | 
				
			|||||||
	"bitbucket.org/nicdex/adaptech-goes"
 | 
						"bitbucket.org/nicdex/adaptech-goes"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
	"encoding/binary"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func main() {
 | 
					func main() {
 | 
				
			||||||
@@ -15,6 +14,7 @@ func main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	//TODO: config/flag
 | 
						//TODO: config/flag
 | 
				
			||||||
	storagePath := path.Join(os.TempDir(), uuid.NewV4().String())
 | 
						storagePath := path.Join(os.TempDir(), uuid.NewV4().String())
 | 
				
			||||||
 | 
						storagePath = "c:\\dev\\go\\events"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	goes.SetStorage(goes.NewDiskStorage(storagePath))
 | 
						goes.SetStorage(goes.NewDiskStorage(storagePath))
 | 
				
			||||||
	goes.SetSerializer(goes.NewPassthruSerializer())
 | 
						goes.SetSerializer(goes.NewPassthruSerializer())
 | 
				
			||||||
@@ -53,7 +53,7 @@ func main() {
 | 
				
			|||||||
				fmt.Println("Wrong format for AggregateId", err)
 | 
									fmt.Println("Wrong format for AggregateId", err)
 | 
				
			||||||
				break
 | 
									break
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			fmt.Println(command, aggregateId.String())
 | 
								fmt.Println("->", command, aggregateId.String())
 | 
				
			||||||
			data := message[2]
 | 
								data := message[2]
 | 
				
			||||||
			err = goes.AddEvent(goes.Event{aggregateId, data})
 | 
								err = goes.AddEvent(goes.Event{aggregateId, data})
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
@@ -66,14 +66,14 @@ func main() {
 | 
				
			|||||||
				fmt.Println("Wrong format for AggregateId", err)
 | 
									fmt.Println("Wrong format for AggregateId", err)
 | 
				
			||||||
				break
 | 
									break
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			fmt.Println(command, aggregateId.String())
 | 
								fmt.Println("->", command, aggregateId.String())
 | 
				
			||||||
			events, err := goes.RetrieveFor(aggregateId)
 | 
								events, err := goes.RetrieveFor(aggregateId)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				panic(err)
 | 
									panic(err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			sendEvents(replySocket, events)
 | 
								sendEvents(replySocket, events)
 | 
				
			||||||
		case "ReadAll":
 | 
							case "ReadAll":
 | 
				
			||||||
			fmt.Println(command)
 | 
								fmt.Println("->", command)
 | 
				
			||||||
			events, err := goes.RetrieveAll()
 | 
								events, err := goes.RetrieveAll()
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				panic(err)
 | 
									panic(err)
 | 
				
			||||||
@@ -85,13 +85,12 @@ func main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func sendEvents(socket *zmq4.Socket, events []*goes.Event) {
 | 
					func sendEvents(socket *zmq4.Socket, events []*goes.Event) {
 | 
				
			||||||
	len := len(events)
 | 
						len := len(events)
 | 
				
			||||||
	lenBytes := make([]byte, 8)
 | 
						socket.Send(fmt.Sprintf("%v", len), zmq4.SNDMORE)
 | 
				
			||||||
	binary.BigEndian.PutUint64(lenBytes, uint64(len))
 | 
					 | 
				
			||||||
	socket.SendBytes(lenBytes, zmq4.SNDMORE)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	i := 0
 | 
						i := 0
 | 
				
			||||||
	for ; i < len-1; i++ {
 | 
						for ; i < len-1; i++ {
 | 
				
			||||||
		socket.SendBytes(events[i].Payload.([]byte), zmq4.SNDMORE)
 | 
							socket.SendBytes(events[i].Payload.([]byte), zmq4.SNDMORE)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	socket.SendBytes(events[i].Payload.([]byte), 0)
 | 
						socket.SendBytes(events[i].Payload.([]byte), 0)
 | 
				
			||||||
 | 
						fmt.Println("<-", len, "events")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user