Skip to content

Commit

Permalink
broker: add publish context (micro#1590)
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Tolstov <[email protected]>
  • Loading branch information
vtolstov authored Apr 28, 2020
1 parent 06220ab commit 9bb1904
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions broker/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ type Option func(*Options)

type PublishOption func(*PublishOptions)

// PublishContext set context
func PublishContext(ctx context.Context) PublishOption {
return func(o *PublishOptions) {
o.Context = ctx
}
}

type SubscribeOption func(*SubscribeOptions)

func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions {
Expand Down
2 changes: 1 addition & 1 deletion client/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func (g *grpcClient) Publish(ctx context.Context, p client.Message, opts ...clie
return g.opts.Broker.Publish(topic, &broker.Message{
Header: md,
Body: body,
})
}, broker.PublishContext(options.Context))
}

func (g *grpcClient) String() string {
Expand Down
2 changes: 1 addition & 1 deletion client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func (r *rpcClient) Publish(ctx context.Context, msg Message, opts ...PublishOpt
return r.opts.Broker.Publish(topic, &broker.Message{
Header: md,
Body: body,
})
}, broker.PublishContext(options.Context))
}

func (r *rpcClient) NewMessage(topic string, message interface{}, opts ...MessageOption) Message {
Expand Down

0 comments on commit 9bb1904

Please sign in to comment.