示例#1
0
        static void Main(string[] args)
        {
            Producer producer = new Producer(TOPIC_NAME, brokerURL);
            Consumer consumer = new Consumer(TOPIC_NAME, brokerURL);

            Console.WriteLine("Connecting to" + brokerURL + " ...");

            consumer.UpdateConnection();
            producer.UpdateConnection();

            Schnorchel schnorch = new Schnorchel();

            schnorch.alter = 17;
            schnorch.name  = "Odd";
            schnorch.hobbies.Add(new Hobby("reiten", false));
            schnorch.hobbies.Add(new Hobby("schwimmen", false));
            schnorch.hobbies.Add(new Hobby("lesen", true));
            schnorch.faehigkeiten.Add("huepfen", true);
            schnorch.faehigkeiten.Add("weidomieren", false);
            schnorch.faehigkeiten.Add("folloppen", true);

            string s = JsonConvert.SerializeObject(schnorch);

            //producer.Send(s);
            Console.ReadKey();
        }
示例#2
0
 // OnMessageReceived - beim messageConsumer registrierte Callback-Methode,
 // wird bei Empfang einer neuen Nachricht vom messageConsumer aufgerufen
 public void OnMessageReceived(IMessage msg)
 {
     if (msg is ITextMessage)
     {
         ITextMessage tm = msg as ITextMessage;
         //Console.WriteLine("TextMessage: ID=" + tm.GetType() + "\n" + tm.Text);
         String s = tm.Text;
         Console.WriteLine(s);
         Schnorchel schnorchel = JsonConvert.DeserializeObject <Schnorchel>(s);
         Console.WriteLine(schnorchel);
     }
     else if (msg is IMapMessage)
     {
         StringBuilder msgbuffer = new StringBuilder();
         IMapMessage   mm        = msg as IMapMessage;
         msgbuffer.AppendFormat("MapMessage: ID={0}\n", msg.GetType());
         foreach (string key in mm.Properties.Keys)
         {
             msgbuffer.AppendFormat("  - Property '{0}' = {1}\n", key, mm.Properties[key]);
         }
         foreach (string key in mm.Body.Keys)
         {
             msgbuffer.AppendFormat("  - Eintrag '{0}' = {1}\n", key, mm.Body[key]);
         }
         Console.WriteLine(msgbuffer.ToString());
     }
     else
     {
         Console.WriteLine("\nAnderer Message-Typ: " + msg);
     }
 }
        static void Main(string[] args)
        {
            Producer producer = new Producer(TOPIC_NAME, brokerURL);
            Consumer consumer = new Consumer(TOPIC_NAME, brokerURL);
            Console.WriteLine("Connecting to" + brokerURL + " ...");

            consumer.UpdateConnection();
            producer.UpdateConnection();

            Schnorchel schnorch = new Schnorchel();
            schnorch.alter = 17;
            schnorch.name = "Odd";
            schnorch.hobbies.Add(new Hobby("reiten", false));
            schnorch.hobbies.Add(new Hobby("schwimmen", false));
            schnorch.hobbies.Add(new Hobby("lesen", true));
            schnorch.faehigkeiten.Add("huepfen", true);
            schnorch.faehigkeiten.Add("weidomieren", false);
            schnorch.faehigkeiten.Add("folloppen", true);

            string s = JsonConvert.SerializeObject(schnorch);
            //producer.Send(s);
            Console.ReadKey();
        }