Beispiel #1
0
        public void Execute(AutoResetEvent block)
        {
            const int filesToCreate  = 10000;
            var       filesProcessed = 0;

            // This setup will emit files on another thread
            new ObservingProducer <int>()
            .Consumes(new FileConsumer <int>())
            .Produces(Observable.Range(1, filesToCreate))
            .Start();

            // This setup will output the contents of loaded files to the console
            var producer = new FileProducer <int>();
            var logger   = new DelegatingConsumer <int>(i =>
            {
                filesProcessed++;
                Console.WriteLine(filesProcessed);
                if (filesProcessed >= filesToCreate)
                {
                    block.Set();
                }
            });

            producer.Attach(logger);
            producer.Start();
        }
Beispiel #2
0
        public void Execute(AutoResetEvent block)
        {
            var producer = new ObservingProducer <int>();
            var consumer = new DelegatingConsumer <int>(i => Console.WriteLine(i));

            producer.Attach(consumer);
            producer.Produces(Observable.Range(1, 10000), onCompleted: () => block.Set());
            producer.Start();
        }
Beispiel #3
0
        public void Execute(AutoResetEvent block)
        {
            var producer = new ObservingProducer<int>();
            var consumer = new DelegatingConsumer<int>(i => Console.WriteLine(i));

            producer.Attach(consumer);
            producer.Produces(Observable.Range(1, 10000), onCompleted: () => block.Set());
            producer.Start();
        }
Beispiel #4
0
        public void Execute(AutoResetEvent block)
        {
            var producer = new ObservingProducer<int>();
            var consumer = new DelegatingConsumer<int>(i => Console.WriteLine(i));

            var serializer = new BinarySerializer();
            var outbound = new ProtocolProducer<int>(serializer);    // This is a producer of a data stream that consumes T events (serializer)
            var inbound = new ProtocolConsumer<int>(serializer);     // This is a consumer of a data stream that produces T events (deserializer)
            outbound.Attach(inbound);                                // Typically you'd put an enqueing consumer here to shuttle serialized events off-network
            inbound.Attach(consumer);

            producer.Attach(outbound);
            producer.Produces(Observable.Range(1, 10000), onCompleted: () => block.Set());
            producer.Start();
        }
Beispiel #5
0
        public void Execute(AutoResetEvent block)
        {
            var producer = new ObservingProducer <int>();
            var consumer = new DelegatingConsumer <int>(i => Console.WriteLine(i));

            var serializer = new BinarySerializer();
            var outbound   = new ProtocolProducer <int>(serializer); // This is a producer of a data stream that consumes T events (serializer)
            var inbound    = new ProtocolConsumer <int>(serializer); // This is a consumer of a data stream that produces T events (deserializer)

            outbound.Attach(inbound);                                // Typically you'd put an enqueing consumer here to shuttle serialized events off-network
            inbound.Attach(consumer);

            producer.Attach(outbound);
            producer.Produces(Observable.Range(1, 10000), onCompleted: () => block.Set());
            producer.Start();
        }
        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();
        }
Beispiel #7
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();
        }
Beispiel #8
0
        public void Execute(AutoResetEvent block)
        {
            const int filesToCreate = 10000;
            var filesProcessed = 0;

            // This setup will emit files on another thread
            new ObservingProducer<int>()
                .Consumes(new FileConsumer<int>())
                .Produces(Observable.Range(1, filesToCreate))
                .Start();

            // This setup will output the contents of loaded files to the console
            var producer = new FileProducer<int>();
            var logger = new DelegatingConsumer<int>(i =>
            {
                filesProcessed++;
                Console.WriteLine(filesProcessed);
                if (filesProcessed >= filesToCreate)
                {
                    block.Set();
                }
            });
            producer.Attach(logger);
            producer.Start();
        }