broker: add publish context (#1590)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-04-28 19:29:00 +03:00 committed by GitHub
parent 06220ab8c8
commit 9bb1904a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -49,6 +49,13 @@ type Option func(*Options)
type PublishOption func(*PublishOptions) type PublishOption func(*PublishOptions)
// PublishContext set context
func PublishContext(ctx context.Context) PublishOption {
return func(o *PublishOptions) {
o.Context = ctx
}
}
type SubscribeOption func(*SubscribeOptions) type SubscribeOption func(*SubscribeOptions)
func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions { func NewSubscribeOptions(opts ...SubscribeOption) SubscribeOptions {

View File

@ -653,7 +653,7 @@ func (g *grpcClient) Publish(ctx context.Context, p client.Message, opts ...clie
return g.opts.Broker.Publish(topic, &broker.Message{ return g.opts.Broker.Publish(topic, &broker.Message{
Header: md, Header: md,
Body: body, Body: body,
}) }, broker.PublishContext(options.Context))
} }
func (g *grpcClient) String() string { func (g *grpcClient) String() string {

View File

@ -628,7 +628,7 @@ func (r *rpcClient) Publish(ctx context.Context, msg Message, opts ...PublishOpt
return r.opts.Broker.Publish(topic, &broker.Message{ return r.opts.Broker.Publish(topic, &broker.Message{
Header: md, Header: md,
Body: body, Body: body,
}) }, broker.PublishContext(options.Context))
} }
func (r *rpcClient) NewMessage(topic string, message interface{}, opts ...MessageOption) Message { func (r *rpcClient) NewMessage(topic string, message interface{}, opts ...MessageOption) Message {