-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
AMQP Transport #746
AMQP Transport #746
Conversation
Cool, this looks reasonable at a first glance. As a next step, please run |
May bad with the underscores.. bad python habits. |
Hey @peterbourgon @mattfung any chance that this moves forward? This would be a great addition along NATS! |
@mattfung I had some issues with running the tests on my end. Rebasing solves all the tests, would you be able to do that? |
I tried the subscriber par only and it worked great! I seems to me that it could be enhanced when looking at Nats.
Which doesn't seem possible without additional code for this implementation since the AMQP client library returns a channel of Deliveries:
and the ServeDelivery process message per message. So you have to create a helper function to listen to the channel and map the ServiceDelivery return to each message. Have you any idea on how to improve this? Or maybe I'm missing something in the implementation... |
make a PR to https://github.com/streadway/amqp with channel listener functionality :) jokes aside, Id be interested on improvements |
Haha yes indeed!
Let’s think about that in another issue ;)
It think this is definitely mergeable! Great job!
… On 17 Oct 2018, at 20:58, Matthew Fung ***@***.***> wrote:
make a PR to https://github.com/streadway/amqp with channel listener functionality :)
jokes aside, Id be interested on improvements
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@peterbourgon Do you have any feedback on this for merging it? I've used it for a professional project as a demonstration (so with small usage), and it ran several days without any issues. |
That’s great feedback, thanks. I just need to block off an hour to review.
I’ll do that in the next 2 days. Sorry for the delay; I have a lot on my
plate these days :/
…On Sun, Nov 4, 2018 at 09:17 Julien ***@***.***> wrote:
@peterbourgon <https://github.com/peterbourgon> Do you have any feedback
on this for merging it? I've used it for a professional project as a
demonstration (so with small usage), and it ran several days without any
issues.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#746 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAG_TUbL68zxAf9rcX0WyAwXrFBm52DYks5uryEIgaJpZM4Vyl8X>
.
|
No worries :) just trying to know if help was needed on that!
…Sent from my iPhone
On 4 Nov 2018, at 19:40, Peter Bourgon ***@***.***> wrote:
That’s great feedback, thanks. I just need to block off an hour to review.
I’ll do that in the next 2 days. Sorry for the delay; I have a lot on my
plate these days :/
On Sun, Nov 4, 2018 at 09:17 Julien ***@***.***> wrote:
> @peterbourgon <https://github.com/peterbourgon> Do you have any feedback
> on this for merging it? I've used it for a professional project as a
> demonstration (so with small usage), and it ran several days without any
> issues.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#746 (comment)>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AAG_TUbL68zxAf9rcX0WyAwXrFBm52DYks5uryEIgaJpZM4Vyl8X>
> .
>
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
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.
A couple of relatively minor design questions, and lots of style nits, most notably that I want proper punctuation for all block comments :) But in general this looks good, with those changes and some explanation, I'm see no problem to merge. Thank you for the great contribution!
transport/amqp/doc.go
Outdated
@@ -0,0 +1,2 @@ | |||
// Package amqp implements a go-kit transport for AMQP |
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.
// Package amqp implements a go-kit transport for AMQP | |
// Package amqp implements an AMQP transport. |
transport/amqp/encode-decode.go
Outdated
type DecodeRequestFunc func(context.Context, *amqp.Delivery) (request interface{}, err error) | ||
|
||
// EncodeRequestFunc encodes the passed request object into | ||
// an AMQP channel for publishing. It is designed to be used in AMQP Publishers |
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.
// an AMQP channel for publishing. It is designed to be used in AMQP Publishers | |
// an AMQP channel for publishing. It is designed to be used in AMQP Publishers. |
transport/amqp/encode-decode.go
Outdated
type EncodeRequestFunc func(context.Context, *amqp.Publishing, interface{}) error | ||
|
||
// EncodeResponseFunc encodes the passed reponse object to | ||
// an AMQP channel for publishing. It is designed to be used in AMQP Subscribers |
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.
// an AMQP channel for publishing. It is designed to be used in AMQP Subscribers | |
// an AMQP channel for publishing. It is designed to be used in AMQP Subscribers. |
transport/amqp/encode-decode.go
Outdated
*amqp.Delivery, Channel, *amqp.Publishing, interface{}) error | ||
|
||
// DecodeResponseFunc extracts a user-domain response object from | ||
// an AMQP Delivery object. It is designed to be used in AMQP Publishers |
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.
// an AMQP Delivery object. It is designed to be used in AMQP Publishers | |
// an AMQP Delivery object. It is designed to be used in AMQP Publishers. |
transport/amqp/publisher.go
Outdated
"github.com/streadway/amqp" | ||
) | ||
|
||
// Publisher wraps AMQP channel and queue and provides a method that |
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.
// Publisher wraps AMQP channel and queue and provides a method that | |
// Publisher wraps an AMQP channel and queue, and provides a method that |
type PublisherResponseFunc func(context.Context, *amqp.Delivery) context.Context | ||
|
||
// SetPublishExchange returns a RequestFunc that sets the Exchange field | ||
// of AMQP Publish call |
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.
Please add ending punctuation (.
) to this and all other header comment blocks in the PR.
transport/amqp/subscriber.go
Outdated
// ReplyErrorEncoder serializes the error message as a DefaultErrorResponse | ||
// JSON and sends the message to the ReplyTo address | ||
func ReplyErrorEncoder(ctx context.Context, | ||
err error, deliv *amqp.Delivery, ch Channel, pub *amqp.Publishing) { |
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.
Please either put the function definition on a single line, or use one parameter per line, e.g.
func Foo(
ctx context.Context,
err error,
deliv *amqp.Delivery,
) {
transport/amqp/publisher.go
Outdated
} | ||
|
||
deliv, err := p.publishAndConsumeFirstMatchingResponse(ctx, &pub) | ||
|
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.
transport/amqp/subscriber.go
Outdated
} | ||
|
||
request, err := s.dec(ctx, deliv) | ||
|
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.
transport/amqp/subscriber.go
Outdated
ctx = f(ctx, deliv, ch, &pub) | ||
} | ||
|
||
if err := s.enc(ctx, deliv, ch, &pub, response); err != nil { |
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.
You're combining "encoding the response to the delivery" with "sending the delivery over AMQP" into a single operation, but my intuition is these should be separate steps, with separate failure modes. Is there a technical reason for that that I'm overlooking?
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.
No good reason other than "cuz the nats transport did it"
I'll separate it to two functions
Sounds good, I'll get them fixed within a day's time. |
Committed the changes. I'm guessing the tests failed because I didn't rebase the code with the latest Anyhow, let me know if anything needs to be changed. |
Tried without (and also with) the rebase locally and I didn't manage to make them fail... Maybe Peter will have an idea. |
Yes, this seems fine; can you rebase on master? |
amqp transport publisher amqp transport tests lint fixes for amqp transport fixed formatting and punctuation zzz default ContentType is null, increased max length of correlationId to 255 refractored subscriber EncodeResponseFunc into encode func, and send func zzz
Dang nice |
@mattfung I am new to gokit and struggling a bit getting AMQP up and working. |
@tlogik for now, heres an implementation of stringsvc4 pub & sub Hope this helps. |
Awesome! Would be great to have it in this repository too, no? |
Thats the plan, my only reservation currently is that the commit makes some breaking changes with the existing |
It helped a lot. Much appreciated. |
Hi again @mattfung i do not seem to be able to setup the internal publisher, in the subscriber.go, for an alternate channel - can you confirm that is not possible in the current implementation? |
@tlogik correct, current implementation does not allow for a subscriber to subscribe to one channel (& consequently, Vhost) and publish to another. I am curious on how other frameworks handle this problem if you happen to know of any. Currently, publishers and subscribers are (for simplicity's sake) tied to one channel. That can change if it is a significant limitation. An alternative approach would be to have a subscriber for vhost A trigger a publisher for vhost B. |
@mattfung currently we use individual instances of subscriber and publisher with individual connstrings. |
@tlogik @mattfung From steadway/amqp's package documentation:
source: https://godoc.org/github.com/streadway/amqp#Channel.Consume So to me the implementation of @mattfung respect perfectly that I like that it's not possible to shoot myself in the foot using this implementation with go-kit. Moreover, the vhosts are part of the connection string, you cannot have 1 channel listening on several vhost, since an amqp channel is some kind of wrapper adding multiplexing to the parent amqp connection which is itself tied to one vhost. @tlogik I guess that if you want to implement that, you can easily consume messages from one channel following @mattfung examples and implement some kind of buffering inside your program in addition of using prefetching (https://godoc.org/github.com/streadway/amqp#Channel.Qos). |
If you're not publishing responses, you're not doing RPC. |
Do you mean this implementation is not about AMQP, but RPC over AMQP? |
@freemanoid Good point, one way AMQP communication is not uncommon. Currently the closest thing to a "no-op" is to use the NopEncoder such that an empty response is sent back. There are two solutions to implement true "no-op" subscribers, one is to make the "encoder" both encode and send, and use The other option is to add an options/ change the parameter to |
Yes. Go kit is concerned exclusively with RPC.
For the record, if this is easy, I'd happily take a PR. |
@mattfung Do you plan any work around adding an option/change parameter to NewSubscriber to no-op subscribers? |
Hello,
I noticed that here had been interest in AMQP transport similiar to NATS (#681) as well as talks of pubsub support (#295) so I thought I might like to share an implementation of a simple AMQP client & server transport.
Comments/Reviews would be appreciated.