[rabbitmq-discuss] Messaging and Serialization in RabbitMQ?

Simone Busoli simone.busoli at gmail.com
Tue Jul 5 22:18:09 BST 2011


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/88034333/attachment.htm>


More information about the rabbitmq-discuss mailing list