private void Done(Task arg1, object c)
        {
            DateTime    tiden = DateTime.Now;
            ZmqConsumer cons  = c as ZmqConsumer;

            Console.WriteLine(cons.name + " Tiden = " + (tiden - start).TotalMilliseconds + " ms");
            Console.WriteLine(cons.name + " Tiden = " + (tiden - start).TotalSeconds + " s");
            wait = false;
        }
        public void Messages_are_queued()
        {
            var block = new AutoResetEvent(false);

            var serializer = new ProtocolBuffersSerializer();
            var socket = new ZmqConsumer<StringEvent>("tcp://127.0.0.1:5000", serializer);
            var consumer = new DelegatingConsumer<StringEvent>(Console.WriteLine, socket); // logs to console before forwarding
            var producer = new ObservingProducer<StringEvent>();

            producer.Attach(consumer);
            producer.Produces(GetPayload(), onCompleted: () => block.Set());
            producer.Start();

            block.WaitOne();
            socket.Dispose();
        }
Exemple #3
0
        public void Messages_are_queued()
        {
            var block = new AutoResetEvent(false);

            var serializer = new ProtocolBuffersSerializer();
            var socket     = new ZmqConsumer <StringEvent>("tcp://127.0.0.1:5000", serializer);
            var consumer   = new DelegatingConsumer <StringEvent>(Console.WriteLine, socket); // logs to console before forwarding
            var producer   = new ObservingProducer <StringEvent>();

            producer.Attach(consumer);
            producer.Produces(GetPayload(), onCompleted: () => block.Set());
            producer.Start();

            block.WaitOne();
            socket.Dispose();
        }
        public void testConsumer()
        {
            for (int i = 0; i < consumers; i++)
            {
                ZmqConsumer c = new ZmqConsumer();
                //pull messages
                string tmp = "Consumer nr. " + (i + 1) + "/" + consumers;

                Task.Run(() => c.StartPull(tmp, antal)).ContinueWith(Done, c);
            }
            start = DateTime.Now;
            ZmqPublicher p = new ZmqPublicher();

            p.create(antal);
            Console.WriteLine("waiting fore reader to complete");
            Console.ReadLine();
        }
Exemple #5
0
        public void Messages_are_dequeued()
        {
            var       block    = new AutoResetEvent(false);
            const int sent     = 10;
            var       received = 0;

            // Anything handled is sent to zmq
            var consumer = new ZmqConsumer <StringEvent>("tcp://127.0.0.1:5000");

            // Anything taken from zmq goes to the console and is counted
            var producer = new ZmqProducer <StringEvent>("tcp://127.0.0.1:5000").Consumes(@event =>
            {
                Console.WriteLine(@event.Text);
                received++;
                if (received >= sent)
                {
                    block.Set();
                }
            });

            producer.Start();

            consumer.Handle(new StringEvent("Test1"));
            consumer.Handle(new StringEvent("Test2"));
            consumer.Handle(new StringEvent("Test3"));
            consumer.Handle(new StringEvent("Test4"));
            consumer.Handle(new StringEvent("Test5"));
            consumer.Handle(new StringEvent("Test6"));
            consumer.Handle(new StringEvent("Test7"));
            consumer.Handle(new StringEvent("Test8"));
            consumer.Handle(new StringEvent("Test9"));
            consumer.Handle(new StringEvent("Test10"));

            block.WaitOne();
            producer.Dispose();
            consumer.Dispose();
        }
        public void Messages_are_dequeued()
        {
            var block = new AutoResetEvent(false);
            const int sent = 10;
            var received = 0;

            // Anything handled is sent to zmq
            var consumer = new ZmqConsumer<StringEvent>("tcp://127.0.0.1:5000");
            
            // Anything taken from zmq goes to the console and is counted
            var producer = new ZmqProducer<StringEvent>("tcp://127.0.0.1:5000").Consumes(@event =>
            {
                Console.WriteLine(@event.Text);
                received++;
                if (received >= sent)
                {
                    block.Set();
                }
            });
            producer.Start();

            consumer.Handle(new StringEvent("Test1"));
            consumer.Handle(new StringEvent("Test2"));
            consumer.Handle(new StringEvent("Test3"));
            consumer.Handle(new StringEvent("Test4"));
            consumer.Handle(new StringEvent("Test5"));
            consumer.Handle(new StringEvent("Test6"));
            consumer.Handle(new StringEvent("Test7"));
            consumer.Handle(new StringEvent("Test8"));
            consumer.Handle(new StringEvent("Test9"));
            consumer.Handle(new StringEvent("Test10"));
            
            block.WaitOne();
            producer.Dispose();
            consumer.Dispose();
        }