Documentation ¶
Overview ¶
Package redis implements an events.PubSub implementation that uses Redis PubSub.
Example ¶
package main import ( "context" "go.thethings.network/lorawan-stack/v3/pkg/config" "go.thethings.network/lorawan-stack/v3/pkg/events" "go.thethings.network/lorawan-stack/v3/pkg/events/redis" "go.thethings.network/lorawan-stack/v3/pkg/task" ) type mockComponent struct { task.Starter } func (mockComponent) FromRequestContext(ctx context.Context) context.Context { return ctx } func main() { // The task starter is used for automatic re-subscription on failure. taskStarter := task.StartTaskFunc(task.DefaultStartTask) redisPubSub := redis.NewPubSub(context.TODO(), mockComponent{taskStarter}, config.RedisEvents{ // Config here... }, config.BatchEvents{ // Batch config here... }) // Replace the default pubsub so that we will now publish to Redis. events.SetDefaultPubSub(redisPubSub) }
Output:
Index ¶
- func NewPubSub(ctx context.Context, component workerpool.Component, conf config.RedisEvents, ...) events.PubSub
- type PubSub
- type PubSubStore
- func (ps *PubSubStore) FetchHistory(ctx context.Context, names []string, ids []*ttnpb.EntityIdentifiers, ...) ([]events.Event, error)
- func (ps *PubSubStore) FindRelated(ctx context.Context, correlationID string) ([]events.Event, error)
- func (ps *PubSubStore) LoadEvent(ctx context.Context, uid string) (*ttnpb.Event, error)
- func (ps *PubSubStore) Publish(evs ...events.Event)
- func (ps *PubSubStore) SubscribeWithHistory(ctx context.Context, names []string, ids []*ttnpb.EntityIdentifiers, ...) (err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewPubSub ¶
func NewPubSub( ctx context.Context, component workerpool.Component, conf config.RedisEvents, batchConf config.BatchEvents, ) events.PubSub
NewPubSub creates a new PubSub that publishes and subscribes to Redis.
Types ¶
type PubSubStore ¶ added in v3.13.0
type PubSubStore struct { *PubSub // contains filtered or unexported fields }
PubSubStore is a PubSub with historical event storage.
func (*PubSubStore) FetchHistory ¶ added in v3.13.0
func (ps *PubSubStore) FetchHistory( ctx context.Context, names []string, ids []*ttnpb.EntityIdentifiers, after *time.Time, tail int, ) ([]events.Event, error)
FetchHistory fetches the tail (optional) of historical events matching the given names (optional) and identifiers (mandatory) after the given time (optional).
func (*PubSubStore) FindRelated ¶ added in v3.13.0
func (ps *PubSubStore) FindRelated(ctx context.Context, correlationID string) ([]events.Event, error)
FindRelated finds events with matching correlation IDs.
func (*PubSubStore) Publish ¶ added in v3.13.0
func (ps *PubSubStore) Publish(evs ...events.Event)
Publish implements events.Publisher.
func (*PubSubStore) SubscribeWithHistory ¶ added in v3.13.0
func (ps *PubSubStore) SubscribeWithHistory( ctx context.Context, names []string, ids []*ttnpb.EntityIdentifiers, after *time.Time, tail int, hdl events.Handler, ) (err error)
SubscribeWithHistory is like FetchHistory, but after fetching historical events, this continues sending live events until the context is done.
Click to show internal directories.
Click to hide internal directories.