本文主要是介绍用delphi xe 开发rabbitmq应用(四),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
读取死信队列
死信队列中的消息由系统自动增加了一些标识属性,x-death(是一个Array),x-first-death-exchange(queue/reason)。
死信队列中的消息如果不是由于异常(publisher代码控制)而进入,由于超时而进入,那其中的消息仍然可以正常读取(消费),只要代码中做特别处理。
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;
vMsgID := aMsg.Header.PropertyList.MessageID.Value;
vAppID := aMsg.Header.PropertyList.AppID.Value;
SiMain.LogString('AppID', aMsg.Header.PropertyList.AppID.Value);
SiMain.LogInteger('TAsyncHello.DecodeMessage-->DeliveryMode', aMsg.Header.PropertyList.DeliveryMode.Value);
SiMain.LogInteger('TAsyncHello.DecodeMessage-->Priority', aMsg.Header.PropertyList.Priority.Value);
SiMain.LogString('TAsyncHello.DecodeMessage-->ContentType', aMsg.Header.PropertyList.ContentType.Value);
//SiMain.LogString('Expiration', aMsg.Header.PropertyList.Expiration.Value);
SiMain.LogString('TAsyncHello.DecodeMessage-->ContentEncoding', aMsg.Header.PropertyList.ContentEncoding.Value);
这篇关于用delphi xe 开发rabbitmq应用(四)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!