package main import ( "context" "log" "11-11.dev/goexamples/elasticstream" ) func main() { ctx := context.Background() // STEP 1: Create a new client client := &elasticstream.Client{} // STEP 2: Configure() the client config := &elasticstream.Config{ Host: "http://test.urantiacloud.com:9200", Indexes: []string{"index-a", "index-b", "index-c"}, BatchSize: 10, DBPath: "./index.db", } err := client.Configure(ctx, config) if err != nil { log.Println("client.Configure() err:", err) return } // ------------ IF RUN FOR THE FIRST TIME ---------------- // STEP 2.5: LifecycleOnCreated() err = client.LifecycleOnCreated(ctx, config) if err != nil { log.Println("client.LifecycleOnCreated() err:", err) return } // ------------ IF RUN FOR THE FIRST TIME ---------------- // ------------ IF CONFIG CHANGED ------------------------ // STEP 2.5: LifecycleOnUpdated() err = client.LifecycleOnUpdated(ctx, config) if err != nil { log.Println("client.LifecycleOnUpdated() err:", err) return } // ------------ IF CONFIG CHANGED ------------------------ // STEP 3: Open() the client err = client.Open(ctx, []Position{}) if err != nil { log.Println("client.Open() err:", err) return } // STEP 4: Read() using client // for untill context is cancelled for { data, err := client.Read(ctx) if err != nil { log.Println("client.Read() err:", err) continue } fmt.Println("data:", data) } // STEP 5: Ack() err = client.Ack(ctx, Position{}) if err != nil { log.Println("client.Ack() err:", err) return } // STEP 6: Teardown() err = client.Teardown(ctx) if err != nil { log.Println("client.Teardown() err:", err) return } }