https://github.com/artyomturkin/go-stream
Common stream abstraction and in-memory implementation for streaming data
https://github.com/artyomturkin/go-stream
stream-processing streaming
Last synced: 5 months ago
JSON representation
Common stream abstraction and in-memory implementation for streaming data
- Host: GitHub
- URL: https://github.com/artyomturkin/go-stream
- Owner: artyomturkin
- License: mit
- Created: 2019-03-24T14:46:54.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-28T09:28:06.000Z (about 7 years ago)
- Last Synced: 2025-08-14T03:26:37.448Z (10 months ago)
- Topics: stream-processing, streaming
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stream abstraction for Go
Common stream abstraction and in-memory implementation for streaming data.
Importing into a project with `go get`
```sh
go get github.com/artyomturkin/go-stream
```
Import into a project with `go mod` support by adding to `go.mod` file
```
require github.com/artyomturkin/go-stream v1.1.2
```
## Abstractions
### Stream
Common structure and configuration for creating streams from providers, consumer and producer interfaces and message structure.
```go
// Stream used to build a Consumer object
type Stream interface {
GetConsumer(ctx context.Context, group string) Consumer
GetProducer(ctx context.Context, group string) Producer
}
```
```go
// Message wraps context and data from stream
type Message struct {
Context context.Context
Data interface{}
}
```
```go
// Consumer provides read access to a message stream
type Consumer interface {
Messages() <-chan Message
Ack(context.Context) error
Nack(context.Context) error
Close() error
Errors() <-chan error
Done() <-chan struct{}
}
```
```go
// Producer provides publish access to a message stream
type Producer interface {
Publish(context.Context, interface{}) error
Close() error
Errors() <-chan error
Done() <-chan struct{}
}
```
```go
// Config common configuration for streams
type Config struct {
Endpoints []string
Topic string
MaxInflightMessages int
Custom interface{}
}
```
### Helper funcs
Functions to set and get tracking information from context
```go
// SetTrackers adds message trackers to context
func SetTrackers(ctx context.Context, tracker ...interface{}) context.Context
```
```go
// GetTrackers returns an array of trackers
func GetTrackers(ctx context.Context) []interface{}
```