publisher => event
This commit is contained in:
parent
dda96cb87e
commit
cb9c4c3aef
16
event.go
Normal file
16
event.go
Normal file
@ -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...)
|
||||
}
|
18
micro.go
18
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
|
||||
|
16
publisher.go
16
publisher.go
@ -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...)
|
||||
}
|
Loading…
Reference in New Issue
Block a user