[rabbitmq-discuss] Messaging and Serialization in RabbitMQ?

Simone Busoli simone.busoli at gmail.com
Tue Jul 5 22:51:24 BST 2011


Putting back the list.

Any chance to have a proper stack trace of the exception?

On Tue, Jul 5, 2011 at 23:46, Demiss Zike <habtdemis at gmail.com> wrote:

> My bad, please ignore my last response. It compiles well but gives me the
> following run time error:
>
> Unhandled Exception: System.InvalidCastException: Unable to cast object of
> type 'RabbitMQ.Events.BasicDeliverEventArgs' to type 'System[]'.
>
>
>
>
> On Tue, Jul 5, 2011 at 4:35 PM, Demiss Zike <habtdemis at gmail.com> wrote:
>
>> It does and take in a byte[] and initializes a Measurement object.
>>
>>
>> On Tue, Jul 5, 2011 at 4:18 PM, Simone Busoli <simone.busoli at gmail.com>wrote:
>>
>>> Doesn't m2 in your code below contain the deserialized message?
>>>
>>> On Tue, Jul 5, 2011 at 23:15, Demiss Zike <habtdemis at gmail.com> wrote:
>>>
>>>> Hello,
>>>>
>>>> I'm using c#. I have a serializable class called Measurement and want to
>>>> send an object of it. I serialized an object of Measurement and captured the
>>>> serialized object as byte[] and published it. My question is how can I
>>>> capture the published message (so that I can deserialize and use it)?
>>>>
>>>> I've included codes on both ends:
>>>>
>>>> public void publish(byte[] _serializedMsg)
>>>> {
>>>> // publisher code
>>>>      ConnectionFactory factory = new ConnectionFactory();
>>>>             factory.HostName = "localhost";
>>>>              using (IConnection connection =
>>>> factory.CreateConnection())
>>>>             using (IModel channel = connection.CreateModel()) {
>>>>             channel.ExchangeDeclare("logs", "fanout");
>>>>             channel.BasicPublish("logs", queue, null, _serializedMsg);
>>>>             Console.WriteLine(" Message sent ");
>>>>         }
>>>> }
>>>>
>>>>
>>>>
>>>> public void subscribe(string queue)
>>>> {
>>>>  // subscriber code
>>>> ConnectionFactory factory = new ConnectionFactory();
>>>>             factory.HostName = "localhost";
>>>>             using (IConnection connection = factory.CreateConnection())
>>>>             using (IModel channel = connection.CreateModel()) {
>>>>             channel.ExchangeDeclare("logs", "fanout");
>>>>
>>>>     string queue1 = channel.QueueDeclare();
>>>>             channel.QueueBind(queue1, "logs", "");
>>>>             QueueingBasicConsumer consumer = new
>>>> QueueingBasicConsumer(channel);
>>>>             channel.BasicConsume(queue1, true, consumer);
>>>>
>>>>             Console.WriteLine(" Waiting for messages. To exit press
>>>> CTRL+C");
>>>>             while(true) {
>>>>                 BasicDeliverEventArgs ea =
>>>>                     (BasicDeliverEventArgs)consumer.Queue.Dequeue();
>>>>                  byte[] body = ea.Body;
>>>>  Measurement m2 = new Measurement(20, 23323, 3.3);
>>>>  m2 = BinarySerialization.BinaryDeSerialize( body );
>>>>
>>>>                 Console.WriteLine(" Message received: ");
>>>>  Console.WriteLine("\nMeasurement ID: {0}", m2.id);
>>>> Console.WriteLine("Measurement Time: {0}", m2.time);
>>>>  Console.WriteLine("Measurement Value: {0}", m2.value);
>>>>             }
>>>>         }
>>>> }
>>>>
>>>>
>>>> Thanks!
>>>> Demi
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> rabbitmq-discuss mailing list
>>>> rabbitmq-discuss at lists.rabbitmq.com
>>>> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20110705/41bd3cc1/attachment.htm>


More information about the rabbitmq-discuss mailing list