Truncate message payloads in the web UI so as not to crash the browser...
This commit is contained in:
parent
c383acd2d2
commit
de965ebce9
|
|
@ -327,13 +327,15 @@ Content-Length: 0</pre>
|
|||
<td>
|
||||
Get messages from a queue. (This is not an HTTP GET as it
|
||||
will alter the state of the queue.) You should post a body looking like:
|
||||
<pre>{"count": 5, "requeue": true}</pre>
|
||||
<pre>{"count": 5, "requeue": true, "truncate": 50000}</pre>
|
||||
to control the (maximum) number of messages you get and
|
||||
whether those messages are requeued. If <code>requeue</code>
|
||||
is false the messages will be removed from the queue. If
|
||||
requeue is true they will be requeued - but their position
|
||||
in the queue may change and their <code>redelivered</code>
|
||||
flag will be set.
|
||||
flag will be set. <code>truncate</code> is optional - if
|
||||
present it will truncate the message payload if it is larger
|
||||
than the size given (in bytes).
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -60,10 +60,11 @@ HELP = {
|
|||
network connections.',
|
||||
|
||||
'message-get-requeue':
|
||||
'Clicking "Get Message(s)" will consume messages from the queue. \
|
||||
'<p>Clicking "Get Message(s)" will consume messages from the queue. \
|
||||
If requeue is set the message will be re-added to the queue, \
|
||||
but ordering will not be preserved and "redelivered" will be set.<br/> \
|
||||
If requeue is not set messages will be removed from the queue.',
|
||||
but ordering will not be preserved and "redelivered" will be set.</p> \
|
||||
<p>If requeue is not set messages will be removed from the queue.</p> \
|
||||
<p>Furthermore, message payloads will be truncated to 50000 bytes.</p>',
|
||||
|
||||
'message-publish-headers':
|
||||
'Headers can have any name. Only long string headers can be set here.',
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@
|
|||
<form action="#/queues/get" method="post">
|
||||
<input type="hidden" name="vhost" value="<%= queue.vhost %>"/>
|
||||
<input type="hidden" name="name" value="<%= queue.name %>"/>
|
||||
<input type="hidden" name="truncate" value="50000"/>
|
||||
<table class="form">
|
||||
<tr>
|
||||
<th><label>Requeue:</label></th>
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ do_it(ReqData, Context) ->
|
|||
Q = rabbit_mgmt_util:id(queue, ReqData),
|
||||
rabbit_mgmt_util:with_decode(
|
||||
[requeue, count, encoding], ReqData, Context,
|
||||
fun([RequeueBin, CountBin, EncBin], _) ->
|
||||
fun([RequeueBin, CountBin, EncBin], Body) ->
|
||||
rabbit_mgmt_util:with_channel(
|
||||
VHost, ReqData, Context,
|
||||
fun (Ch) ->
|
||||
|
|
@ -58,22 +58,27 @@ do_it(ReqData, Context) ->
|
|||
{bad_encoding,
|
||||
EncBin}})
|
||||
end,
|
||||
Trunc = case proplists:get_value(truncate, Body) of
|
||||
undefined -> none;
|
||||
TruncBin -> rabbit_mgmt_util:parse_int(
|
||||
TruncBin)
|
||||
end,
|
||||
rabbit_mgmt_util:reply(
|
||||
basic_gets(Count, Ch, Q, NoAck, Enc),
|
||||
basic_gets(Count, Ch, Q, NoAck, Enc, Trunc),
|
||||
ReqData, Context)
|
||||
end)
|
||||
end).
|
||||
|
||||
basic_gets(0, _, _, _, _) ->
|
||||
basic_gets(0, _, _, _, _, _) ->
|
||||
[];
|
||||
|
||||
basic_gets(Count, Ch, Q, NoAck, Enc) ->
|
||||
case basic_get(Ch, Q, NoAck, Enc) of
|
||||
basic_gets(Count, Ch, Q, NoAck, Enc, Trunc) ->
|
||||
case basic_get(Ch, Q, NoAck, Enc, Trunc) of
|
||||
none -> [];
|
||||
M -> [M | basic_gets(Count - 1, Ch, Q, NoAck, Enc)]
|
||||
M -> [M | basic_gets(Count - 1, Ch, Q, NoAck, Enc, Trunc)]
|
||||
end.
|
||||
|
||||
basic_get(Ch, Q, NoAck, Enc) ->
|
||||
basic_get(Ch, Q, NoAck, Enc, Trunc) ->
|
||||
case amqp_channel:call(Ch, #'basic.get'{queue = Q,
|
||||
no_ack = NoAck}) of
|
||||
{#'basic.get_ok'{redelivered = Redelivered,
|
||||
|
|
@ -87,7 +92,7 @@ basic_get(Ch, Q, NoAck, Enc) ->
|
|||
{routing_key, RoutingKey},
|
||||
{message_count, MessageCount},
|
||||
{properties, rabbit_mgmt_format:basic_properties(Props)}] ++
|
||||
payload_part(Payload, Enc);
|
||||
payload_part(maybe_truncate(Payload, Trunc), Enc);
|
||||
#'basic.get_empty'{} ->
|
||||
none
|
||||
end.
|
||||
|
|
@ -97,6 +102,12 @@ is_authorized(ReqData, Context) ->
|
|||
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
maybe_truncate(Payload, none) -> Payload;
|
||||
maybe_truncate(Payload, Len) when size(Payload) < Len -> Payload;
|
||||
maybe_truncate(Payload, Len) ->
|
||||
<<Start:Len/binary, _Rest/binary>> = Payload,
|
||||
Start.
|
||||
|
||||
payload_part(Payload, Enc) ->
|
||||
{PL, E} = case Enc of
|
||||
auto -> try
|
||||
|
|
|
|||
|
|
@ -717,13 +717,14 @@ get_test() ->
|
|||
#amqp_msg{props = #'P_basic'{headers = Headers},
|
||||
payload = Payload})
|
||||
end,
|
||||
Publish(<<"1">>),
|
||||
Publish(<<"2">>),
|
||||
Publish(<<"3">>),
|
||||
Publish(<<"1aaa">>),
|
||||
Publish(<<"2aaa">>),
|
||||
Publish(<<"3aaa">>),
|
||||
amqp_connection:close(Conn),
|
||||
[Msg] = http_post("/queues/%2f/myqueue/get", [{requeue, false},
|
||||
{count, 1},
|
||||
{encoding, auto}], ?OK),
|
||||
{encoding, auto},
|
||||
{truncate, 1}], ?OK),
|
||||
false = pget(redelivered, Msg),
|
||||
<<>> = pget(exchange, Msg),
|
||||
<<"myqueue">> = pget(routing_key, Msg),
|
||||
|
|
@ -735,8 +736,8 @@ get_test() ->
|
|||
[M2, M3] = http_post("/queues/%2f/myqueue/get", [{requeue, true},
|
||||
{count, 5},
|
||||
{encoding, auto}], ?OK),
|
||||
<<"2">> = pget(payload, M2),
|
||||
<<"3">> = pget(payload, M3),
|
||||
<<"2aaa">> = pget(payload, M2),
|
||||
<<"3aaa">> = pget(payload, M3),
|
||||
2 = length(http_post("/queues/%2f/myqueue/get", [{requeue, false},
|
||||
{count, 5},
|
||||
{encoding, auto}], ?OK)),
|
||||
|
|
|
|||
Loading…
Reference in New Issue