Giter Club home page Giter Club logo

goes's Introduction

GOES is an Event Store golang TCP Library for Go.

Build Status GoDoc Coverage Status Go Report Card

Example

Create a configuration that will be used to describe how to connect to Event Store

//connect to a single node
config := &goes.Configuration{
    ReconnectionDelay:   10000,
    MaxReconnects:       10,
    MaxOperationRetries: 10,
    Address:             "127.0.0.1",
    Port:                1113,
    Login:               "admin",
    Password:            "changeit",
}

//or a cluster via gossip seeds
config := &goes.Configuration{
    ReconnectionDelay:   10000,
    MaxReconnects:       10,
    MaxOperationRetries: 10,
    Login:               "admin",
    Password:            "changeit",
    EndpointDiscoverer:  discoverer = goes.GossipEndpointDiscoverer{
        MaxDiscoverAttempts: 10,
        GossipSeeds:         []string{"http://127.0.0.1:2113", "http://127.0.0.1:1113"},
    }
}

Connect to Event Store

conn, err := goes.NewEventStoreConnection(config)
if err != nil {
	log.Fatalf("[fatal] %s", err.Error())
}
err = conn.Connect()
defer conn.Close()
if err != nil {
	log.Fatalf("[fatal] %s", err.Error())
}

Write events to Event Store

events := []goes.Event{
	goes.Event{
		EventID:   uuid.NewV4(),
		EventType: "itemAdded",
		IsJSON:    true,
		Data:      []byte("{\"price\": \"100\"}"),
		Metadata:  []byte("metadata"),
	},
	goes.Event{
		EventID:   uuid.NewV4(),
		EventType: "itemAdded",
		IsJSON:    true,
		Data:      []byte("{\"price\": \"120\"}"),
		Metadata:  []byte("metadata"),
	},
}

result, err := goes.AppendToStream(conn, "shoppingCart-1", -2, events)
if *result.Result != protobuf.OperationResult_Success {
	log.Printf("[info] WriteEvents failed. %v", result.Result.String())
}
if err != nil {
	log.Printf("[error] WriteEvents failed. %v", err.Error())
}

Reading from Event Store

goes.ReadSingleEvent(conn, "$stats-127.0.0.1:2113", 0, true, true)

LICENSE

Licenced under MIT.

goes's People

Contributors

hayley-jean avatar jen20 avatar jkralik avatar pgermishuys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goes's Issues

SIGSEGV while debugging program

While i debugging i get message about reconnect and after that i get SIGSEGV

The problem is that connection.socket is set to nil during write. From my pointview - closing socket cannot set connection.socket to nil.

LOG:
2018/09/13 11:30:11 [info] connection (id: b775ac4d-13da-470e-9e86-c3a46cd07a7f) reconnected 2018/09/13 11:30:14 [info] closing the connection (id: b775ac4d-13da-470e-9e86-c3a46cd07a7f) to event store... ' 2018/09/13 11:30:14 [error] connection (id: b775ac4d-13da-470e-9e86-c3a46cd07a7f) closed 2018/09/13 11:30:14 [info] connecting (id: b775ac4d-13da-470e-9e86-c3a46cd07a7f) to event store... 2018/09/13 11:30:16 [info] successfully connected to event store on 127.0.0.1:1113 (id: b775ac4d-13da-470e-9e86-c3a46cd07a7f) 2018/09/13 11:30:16 [info] connection (id: b775ac4d-13da-470e-9e86-c3a46cd07a7f) reconnected panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x863ac6] goroutine 57 [running]: github.com/pgermishuys/goes/eventstore.(*TCPPackage).write(0xc4201e7768, 0xc4200c6500, 0x0, 0x0) /home/krz/gocode/src/github.com/pgermishuys/goes/eventstore/tcppackage.go:86 +0x466 github.com/pgermishuys/goes/eventstore.sendPackage(0x200000000, 0xc420204290, 0x10, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...) /home/krz/gocode/src/github.com/pgermishuys/goes/eventstore/connection.go:232 +0xf3 created by github.com/pgermishuys/goes/eventstore.readFromSocket /home/krz/gocode/src/github.com/pgermishuys/goes/eventstore/connection.go:201 +0xb6b

Make subscriptions more go-centric

Having looked at this, it would be nice if subscriptions used go's channel construct.

Doing this would allow the use of a goroutine to process events/errors from subscriptions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.