Exemplo n.º 1
0
//subscribe to a collection shard (pull)
        public virtual void Subscribe(SendChannel <T> channel, Task task)
        {
            //dependes - list people the need to run next
            dependents = dependents.Concat(new Task[] { task }).ToArray();
            //where to send to stuff
            outputChannels = outputChannels.Concat(new SendChannel <T>[] { channel }).ToArray();


            var tempMessage = new Message <T>(null);

            //ask current content for that shard
            //contentes - virtual method each one has to define to create the diff.
            foreach (var record in Contents())
            {
                //Console.WriteLine("Sending {0}", record);

                //if all the message is ready to send - fill up all the message in payload
                if (tempMessage.length == tempMessage.payload.Length)
                {
                    channel.Send(ref tempMessage);

                    tempMessage.length = 0;
                }

                tempMessage.payload[tempMessage.length++] = record;
            }
            //send even if the payload is not full...
            tempMessage.status = MessageStatus.FinalNonEmpty;
            //send to every single channel
            channel.Send(ref tempMessage);
        }
        public void Send(ref Message <Weighted <T> > message)
        {
            newMessage.status = message.status;
            for (int i = 0; i < message.length; i++)
            {
                newMessage.payload[newMessage.length++] = new Weighted <R>(selector(message.payload[i].record), message.payload[i].weight);
            }

            baseChannel.Send(ref newMessage);

            newMessage.length = 0;
        }
        public void Send(ref Message <Weighted <T> > message)
        {
            for (int i = 0; i < message.length; i++)
            {
                var results = selector(message.payload[i].record).ToArray();
                for (int j = 0; j < results.Length; j++)
                {
                    if (newMessage.length == newMessage.payload.Length)
                    {
                        newMessage.status = MessageStatus.Normal;
                        baseChannel.Send(ref newMessage);
                        newMessage.length = 0;
                    }

                    newMessage.payload[newMessage.length++] = new Weighted <R>(results[j], message.payload[i].weight / results.Length);
                }
            }

            newMessage.status = message.status;
            baseChannel.Send(ref newMessage);
            newMessage.length = 0;
        }
        public void Send(ref Message <Weighted <T> > message)
        {
            newMessage.status = message.status;
            for (int i = 0; i < message.length; i++)
            {
                if (predicate(message.payload[i].record))
                {
                    newMessage.payload[newMessage.length++] = message.payload[i];
                }
            }

            baseChannel.Send(ref newMessage);

            newMessage.length = 0;
        }
        public void Send(ref Message <Weighted <T> > message)
        {
            // tamper with the message payload
            for (int i = 0; i < message.length; i++)
            {
                message.payload[i].weight *= -1;
            }

            baseChannel.Send(ref message);

            // un-tamper with the message payload
            for (int i = 0; i < message.length; i++)
            {
                message.payload[i].weight *= -1;
            }
        }
Exemplo n.º 6
0
        public static void Main()
        {
            var conn        = new RabbitMQConnection("amqp://localhost");
            var sendChannel = new SendChannel(conn);


            int i = 0;

            while (i++ < 30)
            {
                Thread.Sleep(1000);
                Console.WriteLine(" [x] Sent {0}", i);
                sendChannel.Send(i, null);
            }

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
Exemplo n.º 7
0
 public void Send(Message m) => SendChannel.Send(m);