예제 #1
0
        public virtual void SerializeObjects()
        {
            string         name = "test-SerializeObjects" + Salt;
            Queue <string> rq   = new Queue <string>(new string[] { "aaa", "aab", "abb", "bbb", "bbc", "bcc", "ccc" });
            Queue <string> wq   = new Queue <string>(new string[] { "aaa", "aab", "abb", "bbb", "bbc", "bcc", "ccc" });

            AbstractChannelsFactory fc = new RabbitMQChannelsFactory();

            Task tr = Task.Factory.StartNew(() => {
                using (IChannelReader <SerializeObjectsData> ch = fc.GetSubscribableChannel <SerializeObjectsData>(name).Subscribe())
                {
                    foreach (SerializeObjectsData item in ch.Enumerate())
                    {
                        Assert.AreEqual(item.OpId, rq.Dequeue());
                    }
                    Assert.IsTrue(ch.Drained);
                }
            });

            Task tw = Task.Factory.StartNew(() => {
                using (IChannelWriter <SerializeObjectsData> ch = fc.GetSubscribableChannel <SerializeObjectsData>(name))
                {
                    while (wq.Count > 0)
                    {
                        ch.Write(new SerializeObjectsData()
                        {
                            OpId = wq.Dequeue(), Status = "test", Message = "/messaggio/lungo/con/sbarre"
                        });
                    }
                    ch.Close();
                }
            });

            Task.WaitAll(tr, tw);
        }
        protected override void RemoteCall(IJobExecutionContext context)
        {
            using (ILoggingOperation log = _logger.NormalOperation())
            {
                log.Wrap(() =>
                {
                    RabbitMQChannelsFactory factory = new RabbitMQChannelsFactory();

                    IChannelWriter <object> ch = null;
                    if (Broadcast)
                    {
                        ch = factory.GetSubscribableChannel <object>(ChannelName);
                    }
                    else
                    {
                        ch = factory.GetChannel <object>(ChannelName);
                    }

                    using (ch)
                    {
                        ch.Write(Message);
                    }
                });
            }
        }