feedkit: split the former maximumdirect.net/weatherd project in two.
feedkit now contains a reusable core, while weatherfeeder is a concrete implementation that includes weather-specific functions.
This commit is contained in:
42
sinks/rabbitmq.go
Normal file
42
sinks/rabbitmq.go
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user