2020-08-28 10:57:42 +03:00
|
|
|
package micro
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-04-11 22:20:37 +03:00
|
|
|
"go.unistack.org/micro/v4/client"
|
2020-08-28 10:57:42 +03:00
|
|
|
)
|
|
|
|
|
2021-01-29 13:17:32 +03:00
|
|
|
// Event is used to publish messages to a topic
|
|
|
|
type Event interface {
|
|
|
|
// Publish publishes a message to the event topic
|
|
|
|
Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:57:42 +03:00
|
|
|
type event struct {
|
|
|
|
c client.Client
|
|
|
|
topic string
|
|
|
|
}
|
|
|
|
|
2021-01-29 13:17:32 +03:00
|
|
|
// NewEvent creates a new event publisher
|
|
|
|
func NewEvent(topic string, c client.Client) Event {
|
|
|
|
return &event{c, topic}
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:57:42 +03:00
|
|
|
func (e *event) Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error {
|
|
|
|
return e.c.Publish(ctx, e.c.NewMessage(e.topic, msg), opts...)
|
|
|
|
}
|