-
Notifications
You must be signed in to change notification settings - Fork 28
Propagate x-headers in SEND and SUBSCRIBE to queue.declare #27
Conversation
x-dead-letter-exchange, x-dead-letter-routing-key and x-max-priority parsing in SEND and SUBSCRIBE
0c130da
to
4f1718f
Compare
|
||
ensure_endpoint(Direction, Endpoint, _Frame, Channel, State) -> | ||
rabbit_routing_util:ensure_endpoint(Direction, Channel, Endpoint, State). | ||
{_, _, Headers, _} = Frame, |
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 can destructure right in the head argument list.
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.
Also in this case Frame is unbound, since the argument above is _Frame.
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.
Scratch my comment, I misunderstood the diff
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, could you provide an example?
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.
@michaelklishin or better, what is the idiomatic erlang way?
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.
Instead of having something like: ensure_endpoint(Direction, Endpoint, Frame, Channel, State)
you can do ensure_endpoint(Direction, Endpoint, {_, _, Headers, _} = Frame, Channel, State)
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.
@videlalvaro clever! thanks. and in the function do I get both Headers and Frame in scope?
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.
Álvaro's example is what I had in mind.
build_argument(?HEADER_X_MAX_PRIORITY, Val) -> | ||
{list_to_binary(?HEADER_X_MAX_PRIORITY), long, list_to_integer(string:strip(Val))}; | ||
build_argument(?HEADER_X_MESSAGE_TTL, Val) -> | ||
{list_to_binary(?HEADER_X_MESSAGE_TTL), long, list_to_integer(string:strip(Val))}. |
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.
I think this function can be refactored to not repeat almost the same function body in the different clauses. What changes is the type of the argument, long
, longstr
, and so on.
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.
it's very declarative and small, though. Without proper macroexpansion capabilities in Erlang I'd leave it as is.
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.
Key and value conversion to binary can probably happen before build_argument is called.
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.
I would leave as it is. As you said, it's declarative and small. IMO, key and value conversion is exactly the responsibility of the 'build_argument' function, in fact it's different for each header.
Propagate x-headers in SEND and SUBSCRIBE to queue.declare
Fixes #13.