feedkit now contains a reusable core, while weatherfeeder is a concrete implementation that includes weather-specific functions.
43 lines
952 B
Go
43 lines
952 B
Go
package sinks
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/ejr/feedkit/config"
|
|
"gitea.maximumdirect.net/ejr/feedkit/event"
|
|
)
|
|
|
|
type RabbitMQSink struct {
|
|
name string
|
|
url string
|
|
exchange string
|
|
}
|
|
|
|
func NewRabbitMQSinkFromConfig(cfg config.SinkConfig) (Sink, error) {
|
|
url, err := requireStringParam(cfg, "url")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ex, err := requireStringParam(cfg, "exchange")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &RabbitMQSink{name: cfg.Name, url: url, exchange: ex}, nil
|
|
}
|
|
|
|
func (r *RabbitMQSink) Name() string { return r.name }
|
|
|
|
func (r *RabbitMQSink) Consume(ctx context.Context, e event.Event) error {
|
|
_ = ctx
|
|
|
|
// Boundary validation: if something upstream violated invariants,
|
|
// surface it loudly rather than printing partial nonsense.
|
|
if err := e.Validate(); err != nil {
|
|
return fmt.Errorf("rabbitmq sink: invalid event: %w", err)
|
|
}
|
|
|
|
// TODO implement RabbitMQ publishing
|
|
return nil
|
|
}
|