diff --git a/event.go b/event.go new file mode 100644 index 00000000..5301c747 --- /dev/null +++ b/event.go @@ -0,0 +1,16 @@ +package micro + +import ( + "context" + + "github.com/micro/go-micro/client" +) + +type event struct { + c client.Client + topic string +} + +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...) +} diff --git a/micro.go b/micro.go index a8cb7368..6dc43848 100644 --- a/micro.go +++ b/micro.go @@ -62,12 +62,15 @@ type Resource interface { } */ -// Publisher is uses to publish messages to a topic -type Publisher interface { +// 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 } +// Type alias to satisfy the deprecation +type Publisher = Event + type Option func(*Options) var ( @@ -95,12 +98,17 @@ func NewFunction(opts ...Option) Function { return newFunction(opts...) } -// NewPublisher returns a new Publisher -func NewPublisher(topic string, c client.Client) Publisher { +// NewEvent creates a new event publisher +func NewEvent(topic string, c client.Client) Event { if c == nil { c = client.NewClient() } - return &publisher{c, topic} + return &event{c, topic} +} + +// Deprecated: NewPublisher returns a new Publisher +func NewPublisher(topic string, c client.Client) Event { + return NewEvent(topic, c) } // RegisterHandler is syntactic sugar for registering a handler diff --git a/publisher.go b/publisher.go deleted file mode 100644 index c3bfbff3..00000000 --- a/publisher.go +++ /dev/null @@ -1,16 +0,0 @@ -package micro - -import ( - "context" - - "github.com/micro/go-micro/client" -) - -type publisher struct { - c client.Client - topic string -} - -func (p *publisher) Publish(ctx context.Context, msg interface{}, opts ...client.PublishOption) error { - return p.c.Publish(ctx, p.c.NewMessage(p.topic, msg), opts...) -}