38 lines
678 B
Go
38 lines
678 B
Go
package elastic
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
"elasticstream/opencdc"
|
|
)
|
|
|
|
func (c *Client) Read(context.Context) (*opencdc.Data, error) {
|
|
log.Println(">>>> elastic.Read()")
|
|
defer log.Println("<<<< elastic.Read()")
|
|
|
|
if c == nil || c.ch == nil {
|
|
return nil, fmt.Errorf("error source not opened for reading")
|
|
}
|
|
|
|
data, ok := <-c.ch
|
|
if !ok {
|
|
return nil, fmt.Errorf("error reading data from channel")
|
|
}
|
|
|
|
index := data.Header.Index
|
|
if !ok {
|
|
return nil, fmt.Errorf("error index not found in data header")
|
|
}
|
|
|
|
offset, ok := c.offsets[index]
|
|
if !ok {
|
|
return nil, fmt.Errorf("error offset index not found")
|
|
}
|
|
|
|
c.offsets[index] = offset + 1
|
|
|
|
return &data, nil
|
|
}
|