【develope rabbitmq client for delphi xe】-part2


【develope rabbitmq client for delphi xe】-part2

The MSG in the dead-letter queue is automatically added by the system to some identity attributes, x-death (which is an Array), and x-first-death-exchange (queue/reason). If the message in the dead-letter queue enters because it is not due to an exception (publisher code control), it enters due to timeout, and the message can still be read (consumed) normally, as long as the code does special processing.

try
//解码Header,如果从死信队列接收,其中还有 (x-death) Array
with aMsg.Header.PropertyList.ApplicationHeaders do
begin
if IsFieldExist('x-death') then
begin
vDeath := Field['x-death'].AsArray;

if vDeath.Items[0].kind = 'F' then
begin
vTable := vDeath.Items[0].CastAsTable;
SiMain.LogInt64('TAsyncHello.DecodeMessage->count', vTable.FieldByName('count').Value.AsLongLongInt.Value);
SiMain.LogString('TAsyncHello.DecodeMessage->reason', vTable.StringByName('reason'));
SiMain.LogString('TAsyncHello.DecodeMessage->queue', vTable.StringByName('queue'));
SiMain.LogString('TAsyncHello.DecodeMessage->exchange', vTable.StringByName('exchange'));
//SiMain.LogString('x-first-death-exchange', vTable.StringByName('x-first-death-exchange'));

end;
end;
if IsFieldExist('x-first-death-exchange') then
SiMain.LogString('x-first-death-exchange', StringByName('x-first-death-exchange'));

if IsFieldExist('x-first-death-queue') then
SiMain.LogString('x-first-death-queue', StringByName('x-first-death-queue'));

if IsFieldExist('x-first-death-reason') then
SiMain.LogString('x-first-death-reason', StringByName('x-first-death-reason'));
end;
Except on E: Exception do
begin
siMain.LogException('解码消息头错误:' + E.Message);
MainForm.MemoMessages.Lines.Add('解码消息头错误:' + E.Message);
end;
end;

Comments