Hello,<div><br></div><div>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)?��</div>
<div><br></div><div>I've included codes on both ends:</div><div><br></div><div><div>public void publish(byte[] _serializedMsg)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>// publisher code</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>� � ConnectionFactory factory = new ConnectionFactory();</div><div>� � � � � � factory.HostName = "localhost";<span class="Apple-tab-span" style="white-space:pre"> </span></div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div>� � � � � � using (IConnection connection = factory.CreateConnection())</div><div>� � � � � � using (IModel channel = connection.CreateModel()) {</div>
<div>� � � � � � channel.ExchangeDeclare("logs", "fanout");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div>� � � � � � channel.BasicPublish("logs", queue, null, _serializedMsg);</div>
<div>� � � � � � Console.WriteLine(" Message sent ");</div><div>� � � � }</div><div>}</div></div><div><br></div><div><br></div><div><br></div><div><div>public void subscribe(string queue)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>// subscriber code</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ConnectionFactory factory = new ConnectionFactory();</div><div>
� � � � � � factory.HostName = "localhost";</div><div>� � � � � � using (IConnection connection = factory.CreateConnection())</div><div>� � � � � � using (IModel channel = connection.CreateModel()) {</div><div>� � � � � � channel.ExchangeDeclare("logs", "fanout");</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>� ��string queue1 = channel.QueueDeclare();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div>� � � � � � channel.QueueBind(queue1, "logs", "");</div>
<div>� � � � � � QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);</div><div>� � � � � � channel.BasicConsume(queue1, true, consumer);</div><div><br></div><div>� � � � � � Console.WriteLine(" Waiting for messages. To exit press CTRL+C");</div>
<div>� � � � � � while(true) {</div><div>� � � � � � � � BasicDeliverEventArgs ea =</div><div>� � � � � � � � � � (BasicDeliverEventArgs)consumer.Queue.Dequeue();</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div>
<div>� � � � � � � � byte[] body = ea.Body;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Measurement m2 = new Measurement(20, 23323, 3.3);</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>m2 = BinarySerialization.BinaryDeSerialize( body );</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>� � � � � � � ��</div><div>� � � � � � � � Console.WriteLine(" Message received: ");</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>Console.WriteLine("\nMeasurement ID: {0}", <a href="http://m2.id">m2.id</a>);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Console.WriteLine("Measurement Time: {0}", m2.time);</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>Console.WriteLine("Measurement Value: {0}", m2.value);</div><div>� � � � � � }</div><div>� � � � }</div><div>}<span class="Apple-tab-span" style="white-space:pre"> </span></div>
</div><div><br></div><div><br></div><div>Thanks!</div><div>Demi</div><div><br></div><div><br></div><div><br></div><div><br></div>