[rabbitmq-discuss] Decoding header fields
Bernhard Mogens Ege
bme at saseco.dk
Wed Aug 1 12:07:19 BST 2012
I have looked at SingleGet, but I don't think I understand AMQP messages at
all if BasicGet return just 1 object which can be string, int, etc. How is
the header of the message accessed?
Anyway, I am not using BasicGet, but EventingBasicConsumer (callback)
provided to BasicConsume. My callback method gets the BsicDeliverEventArgs
where I can access BasicComsumer and through that, the Headers, where I
extract, using my key, the Value I seek. But GetType() always says the value
is of type System.Byte[].
I have a method like this (I'll make it use string,object instead of
string,string eventually):
public void sendMessage(string routingKey, Dictionary<string,string>
headers, byte[] payload)
{
lock (channel)
{
IMapMessageBuilder b = new MapMessageBuilder(channel);
foreach (var header in headers)
{
b.Headers[header.Key] = header.Value;
}
channel.BasicPublish(ExchangeName, routingKey, false, true,
(IBasicProperties)b.GetContentHeader(), payload);
}
}
And could be call like this:
sendMessage("myroutingkey", new Dictionary<string, string> { { "languageid",
"1" } }, null);
And when received in the callback, printed like this:
Console.Write("type of languageid: " +
e.BasicProperties.Headers["languageid"].GetType());
And it prints: System.Byte[]
I must have missed something somewhere. :-/
I appreciate the help. :)
--
Bernhard
-----Original Message-----
From: Emile Joubert [mailto:emile at rabbitmq.com]
Sent: 1. august 2012 12:28
To: bme at saseco.dk
Cc: 'Discussions about RabbitMQ'
Subject: Re: [rabbitmq-discuss] Decoding header fields
Hi Bernhard,
On 30/07/12 13:44, Bernhard Mogens Ege wrote:
> I have now looked at the SendMap example and replicated its function
> in my own program, but I still receive header fields as Byte[].
>
> How do I make RabbitMQ decode my header fields to the correct type?
The combination of the SendMap.exe and SingleGet.exe examples show how
arbitrary types of header can be sent and received, and that AMQP types are
mapped to .net types. In particular look at
DumpUtil.DumpProperties() which illustrate how to recognise different types.
If you are still only seeing byte arrays then make sure you aren't
implicitly casting to that type somewhere.
-Emile
More information about the rabbitmq-discuss
mailing list