-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1039 Migrate azure/go-amqp to version 1.0.5 #1040
Open
cx-joses
wants to merge
1
commit into
cloudevents:main
Choose a base branch
from
cx-joses:main
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,8 @@ import ( | |
) | ||
|
||
type Protocol struct { | ||
connOpts []amqp.ConnOption | ||
sessionOpts []amqp.SessionOption | ||
senderLinkOpts []amqp.LinkOption | ||
receiverLinkOpts []amqp.LinkOption | ||
|
||
// AMQP | ||
Client *amqp.Client | ||
Client *amqp.Conn | ||
Session *amqp.Session | ||
ownedClient bool | ||
Node string | ||
|
@@ -35,54 +30,60 @@ type Protocol struct { | |
} | ||
|
||
// NewProtocolFromClient creates a new amqp transport. | ||
func NewProtocolFromClient(client *amqp.Client, session *amqp.Session, queue string, opts ...Option) (*Protocol, error) { | ||
func NewProtocolFromClient( | ||
ctx context.Context, | ||
client *amqp.Conn, | ||
session *amqp.Session, | ||
queue string, | ||
senderOptions amqp.SenderOptions, | ||
receiverOptions amqp.ReceiverOptions, | ||
) (*Protocol, error) { | ||
t := &Protocol{ | ||
Node: queue, | ||
senderLinkOpts: []amqp.LinkOption(nil), | ||
receiverLinkOpts: []amqp.LinkOption(nil), | ||
Client: client, | ||
Session: session, | ||
} | ||
if err := t.applyOptions(opts...); err != nil { | ||
return nil, err | ||
Node: queue, | ||
Client: client, | ||
Session: session, | ||
} | ||
|
||
t.senderLinkOpts = append(t.senderLinkOpts, amqp.LinkTargetAddress(queue)) | ||
|
||
// Create a sender | ||
amqpSender, err := session.NewSender(t.senderLinkOpts...) | ||
amqpSender, err := session.NewSender(ctx, queue, &senderOptions) | ||
if err != nil { | ||
_ = client.Close() | ||
_ = session.Close(context.Background()) | ||
return nil, err | ||
} | ||
t.Sender = NewSender(amqpSender).(*sender) | ||
t.Sender = NewSender(amqpSender, &amqp.SendOptions{}).(*sender) | ||
t.SenderContextDecorators = []func(context.Context) context.Context{} | ||
|
||
t.receiverLinkOpts = append(t.receiverLinkOpts, amqp.LinkSourceAddress(t.Node)) | ||
amqpReceiver, err := t.Session.NewReceiver(t.receiverLinkOpts...) | ||
amqpReceiver, err := t.Session.NewReceiver(ctx, t.Node, &receiverOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
t.Receiver = NewReceiver(amqpReceiver).(*receiver) | ||
t.Receiver = NewReceiver(amqpReceiver, amqp.ReceiveOptions{}).(*receiver) | ||
return t, nil | ||
} | ||
|
||
// NewProtocol creates a new amqp transport. | ||
func NewProtocol(server, queue string, connOption []amqp.ConnOption, sessionOption []amqp.SessionOption, opts ...Option) (*Protocol, error) { | ||
client, err := amqp.Dial(server, connOption...) | ||
func NewProtocol( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question as above |
||
ctx context.Context, | ||
server, queue string, | ||
connOptions amqp.ConnOptions, | ||
sessionOptions amqp.SessionOptions, | ||
senderOptions amqp.SenderOptions, | ||
receiverOptions amqp.ReceiverOptions, | ||
) (*Protocol, error) { | ||
client, err := amqp.Dial(ctx, server, &connOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Open a session | ||
session, err := client.NewSession(sessionOption...) | ||
session, err := client.NewSession(ctx, &sessionOptions) | ||
if err != nil { | ||
_ = client.Close() | ||
return nil, err | ||
} | ||
|
||
p, err := NewProtocolFromClient(client, session, queue, opts...) | ||
p, err := NewProtocolFromClient(ctx, client, session, queue, senderOptions, receiverOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -92,69 +93,70 @@ func NewProtocol(server, queue string, connOption []amqp.ConnOption, sessionOpti | |
} | ||
|
||
// NewSenderProtocolFromClient creates a new amqp sender transport. | ||
func NewSenderProtocolFromClient(client *amqp.Client, session *amqp.Session, address string, opts ...Option) (*Protocol, error) { | ||
func NewSenderProtocolFromClient( | ||
ctx context.Context, | ||
client *amqp.Conn, | ||
session *amqp.Session, | ||
address string, | ||
senderOptions amqp.SenderOptions, | ||
) (*Protocol, error) { | ||
t := &Protocol{ | ||
Node: address, | ||
senderLinkOpts: []amqp.LinkOption(nil), | ||
receiverLinkOpts: []amqp.LinkOption(nil), | ||
Client: client, | ||
Session: session, | ||
Node: address, | ||
Client: client, | ||
Session: session, | ||
} | ||
if err := t.applyOptions(opts...); err != nil { | ||
return nil, err | ||
} | ||
t.senderLinkOpts = append(t.senderLinkOpts, amqp.LinkTargetAddress(address)) | ||
|
||
// Create a sender | ||
amqpSender, err := session.NewSender(t.senderLinkOpts...) | ||
amqpSender, err := session.NewSender(ctx, address, &senderOptions) | ||
if err != nil { | ||
_ = client.Close() | ||
_ = session.Close(context.Background()) | ||
return nil, err | ||
} | ||
t.Sender = NewSender(amqpSender).(*sender) | ||
t.Sender = NewSender(amqpSender, &amqp.SendOptions{}).(*sender) | ||
t.SenderContextDecorators = []func(context.Context) context.Context{} | ||
|
||
return t, nil | ||
} | ||
|
||
// NewReceiverProtocolFromClient creates a new receiver amqp transport. | ||
func NewReceiverProtocolFromClient(client *amqp.Client, session *amqp.Session, address string, opts ...Option) (*Protocol, error) { | ||
func NewReceiverProtocolFromClient( | ||
ctx context.Context, | ||
client *amqp.Conn, | ||
session *amqp.Session, | ||
address string, | ||
receiverOptions amqp.ReceiverOptions, | ||
) (*Protocol, error) { | ||
t := &Protocol{ | ||
Node: address, | ||
senderLinkOpts: []amqp.LinkOption(nil), | ||
receiverLinkOpts: []amqp.LinkOption(nil), | ||
Client: client, | ||
Session: session, | ||
} | ||
if err := t.applyOptions(opts...); err != nil { | ||
return nil, err | ||
Node: address, | ||
Client: client, | ||
Session: session, | ||
} | ||
|
||
t.Node = address | ||
t.receiverLinkOpts = append(t.receiverLinkOpts, amqp.LinkSourceAddress(address)) | ||
amqpReceiver, err := t.Session.NewReceiver(t.receiverLinkOpts...) | ||
amqpReceiver, err := t.Session.NewReceiver(ctx, address, &receiverOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
t.Receiver = NewReceiver(amqpReceiver).(*receiver) | ||
t.Receiver = NewReceiver(amqpReceiver, amqp.ReceiveOptions{}).(*receiver) | ||
return t, nil | ||
} | ||
|
||
// NewSenderProtocol creates a new sender amqp transport. | ||
func NewSenderProtocol(server, address string, connOption []amqp.ConnOption, sessionOption []amqp.SessionOption, opts ...Option) (*Protocol, error) { | ||
client, err := amqp.Dial(server, connOption...) | ||
func NewSenderProtocol(ctx context.Context, server, address string, connOptions amqp.ConnOptions, sessionOptions amqp.SessionOptions, senderOptions amqp.SenderOptions) (*Protocol, error) { | ||
client, err := amqp.Dial(ctx, server, &connOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Open a session | ||
session, err := client.NewSession(sessionOption...) | ||
session, err := client.NewSession(ctx, &sessionOptions) | ||
if err != nil { | ||
_ = client.Close() | ||
return nil, err | ||
} | ||
|
||
p, err := NewSenderProtocolFromClient(client, session, address, opts...) | ||
p, err := NewSenderProtocolFromClient(ctx, client, session, address, senderOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -164,20 +166,20 @@ func NewSenderProtocol(server, address string, connOption []amqp.ConnOption, ses | |
} | ||
|
||
// NewReceiverProtocol creates a new receiver amqp transport. | ||
func NewReceiverProtocol(server, address string, connOption []amqp.ConnOption, sessionOption []amqp.SessionOption, opts ...Option) (*Protocol, error) { | ||
client, err := amqp.Dial(server, connOption...) | ||
func NewReceiverProtocol(ctx context.Context, server, address string, connOptions amqp.ConnOptions, sessionOptions amqp.SessionOptions, receiverOptions amqp.ReceiverOptions) (*Protocol, error) { | ||
client, err := amqp.Dial(ctx, server, &connOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Open a session | ||
session, err := client.NewSession(sessionOption...) | ||
session, err := client.NewSession(ctx, &sessionOptions) | ||
if err != nil { | ||
_ = client.Close() | ||
return nil, err | ||
} | ||
|
||
p, err := NewReceiverProtocolFromClient(client, session, address, opts...) | ||
p, err := NewReceiverProtocolFromClient(ctx, client, session, address, receiverOptions) | ||
|
||
if err != nil { | ||
return nil, err | ||
|
@@ -187,15 +189,6 @@ func NewReceiverProtocol(server, address string, connOption []amqp.ConnOption, s | |
return p, nil | ||
} | ||
|
||
func (t *Protocol) applyOptions(opts ...Option) error { | ||
for _, fn := range opts { | ||
if err := fn(t); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (t *Protocol) Close(ctx context.Context) (err error) { | ||
if t.ownedClient { | ||
// Closing the client will close at cascade sender and receiver | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: are we ok with this breaking change on this signature? I understand why we technically might not need options anymore (since those are now structs), but you might want to keep the options pattern to not break this signature and allow for future expansions. You could introduce a new option to set sender/receiver options on the protocol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or are you worried that those two structs are always needed and thus an options pattern doesn't really apply?