Beispiel #1
0
                public SendAsyncResult(ServerCompositeDuplexChannel outer, Message message, TimeSpan timeout, AsyncCallback callback, object state)
                    : base(callback, state)
                {
                    this.timeoutHelper = new TimeoutHelper(timeout);
                    this.outputChannel = outer.ValidateStateAndGetOutputChannel(message, timeoutHelper);

                    bool success = false;

                    try
                    {
                        IAsyncResult result = outputChannel.BeginSend(message, timeoutHelper.RemainingTime(), sendCompleteCallback, this);
                        if (result.CompletedSynchronously)
                        {
                            CompleteSend(result);
                            this.Complete(true);
                        }
                        success = true;
                    }
                    finally
                    {
                        if (!success)
                        {
                            this.outputChannel.Abort();
                        }
                    }
                }
Beispiel #2
0
        private void SendMessage(IOutputChannel channel, string action, bool commit)
        {
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                Message message = Message.CreateMessage(MessageVersion.Default, action);

                if (this.Parameters.AsyncSend)
                {
                    IAsyncResult result = channel.BeginSend(message, null, null);
                    channel.EndSend(result);
                }
                else
                {
                    channel.Send(message);
                }

                if (commit)
                {
                    ts.Complete();
                }
                else
                {
                    Transaction.Current.Rollback();
                }
            }
        }
Beispiel #3
0
        private void SendMessages(TimeSpan channelTimeout, TimeSpan messageSendTimeout)
        {
            ChannelFactory <IOutputChannel> channelFactory =
                new ChannelFactory <IOutputChannel>(Util.GetBinding(), Queue);
            IOutputChannel proxy = channelFactory.CreateChannel();

            IAsyncResult[] resultArray = new IAsyncResult[MessageCount];

            for (int i = 0; i < MessageCount; i++)
            {
                Message toSend = Message.CreateMessage(MessageVersion.Default, string.Empty, i);
                resultArray[i] = proxy.BeginSend(toSend, messageSendTimeout, null, null);
            }

            for (int j = 0; j < MessageCount; j++)
            {
                proxy.EndSend(resultArray[j]);
            }

            IAsyncResult iocCloseResult = proxy.BeginClose(channelTimeout, null, null);

            Thread.Sleep(TimeSpan.FromMilliseconds(50.0)); // Dummy work
            proxy.EndClose(iocCloseResult);

            IAsyncResult chanFactCloseResult = channelFactory.BeginClose(channelTimeout, null, null);

            Thread.Sleep(TimeSpan.FromMilliseconds(50.0)); // Dummy work
            channelFactory.EndClose(chanFactCloseResult);
        }
Beispiel #4
0
        public IAsyncResult BeginSend(Message message, TimeSpan timeout,
                                      AsyncCallback callback, object state)
        {
            // Apply the context information before sending the message.
            this.ApplyContext(message);

            return(innerOutputChannel.BeginSend(message, timeout,
                                                callback, state));
        }
        public SendAsyncResult(IOutputChannel innerChannel, Message message, TimeSpan timeout, AsyncCallback onSendDone, AsyncCallback callback, object state, DependencyTelemetry telemetry)
            : base(onSendDone, callback, state, telemetry)
        {
            this.InnerChannel = innerChannel;
            this.RequestId    = message.Headers.MessageId;

            this.OriginalResult = innerChannel.BeginSend(message, timeout, OnComplete, this);
            if (this.OriginalResult.CompletedSynchronously)
            {
                innerChannel.EndSend(this.OriginalResult);
                this.Complete(true);
            }
        }
Beispiel #6
0
                public SendAsyncResult(IOutputChannel channel, Message message, TimeSpan timeout, AsyncCallback callback, object state)
                    : base(callback, state)
                {
                    if (message != null)
                    {
                        this.channel = channel;

                        IAsyncResult sendResult = channel.BeginSend(message, timeout, sendCallback, this);
                        if (!sendResult.CompletedSynchronously)
                        {
                            return;
                        }

                        CompleteSend(sendResult);
                    }

                    base.Complete(true);
                }
Beispiel #7
0
 public IAsyncResult BeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(_channel.BeginSend(message, timeout, callback, state));
 }
Beispiel #8
0
 protected virtual IAsyncResult OnBeginSend(Message message, TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(inner.BeginSend(message, timeout, callback, state));
 }
Beispiel #9
0
        public void Run()
        {
            IRawBodyUtility bodyUtil = new RawEncoderUtility();

            IInputChannel  startQueue     = null;
            IOutputChannel doneQueue      = null;
            UInt64         batchSize      = (UInt64)opts.pubTxSize;
            bool           txPending      = false;
            AmqpProperties amqpProperties = null;

            if (opts.durable)
            {
                amqpProperties         = new AmqpProperties();
                amqpProperties.Durable = true;
            }

            try
            {
                publishQueue = QueueChannelFactory.CreateWriterChannel(this.destination, this.routingKey);
                doneQueue    = QueueChannelFactory.CreateWriterChannel("", this.Fqn("pub_done"));
                startQueue   = QueueChannelFactory.CreateReaderChannel(this.Fqn("pub_start"));

                // wait for our start signal
                Message msg;
                msg = startQueue.Receive(TimeSpan.MaxValue);
                Expect(bodyUtil.GetText(msg), "start");
                msg.Close();

                Stopwatch     stopwatch    = new Stopwatch();
                AsyncCallback sendCallback = new AsyncCallback(this.AsyncSendCB);

                byte[]       data       = new byte[this.msgSize];
                IAsyncResult sendResult = null;

                Console.WriteLine("sending {0}", this.msgCount);
                stopwatch.Start();

                if (batchSize > 0)
                {
                    Transaction.Current = new CommittableTransaction();
                }

                for (UInt64 i = 0; i < this.msgCount; i++)
                {
                    StampSequenceNo(data, i);
                    msg = bodyUtil.CreateMessage(data);
                    if (amqpProperties != null)
                    {
                        msg.Properties.Add("AmqpProperties", amqpProperties);
                    }

                    sendResult = publishQueue.BeginSend(msg, TimeSpan.MaxValue, sendCallback, msg);

                    if (batchSize > 0)
                    {
                        txPending = true;
                        if (((i + 1) % batchSize) == 0)
                        {
                            ((CommittableTransaction)Transaction.Current).Commit();
                            txPending           = false;
                            Transaction.Current = new CommittableTransaction();
                        }
                    }
                }

                if (txPending)
                {
                    ((CommittableTransaction)Transaction.Current).Commit();
                }

                Transaction.Current = null;

                sendResult.AsyncWaitHandle.WaitOne();
                stopwatch.Stop();

                double mps = (msgCount / stopwatch.Elapsed.TotalSeconds);

                msg = bodyUtil.CreateMessage(String.Format("{0:0.##}", mps));
                doneQueue.Send(msg, TimeSpan.MaxValue);
                msg.Close();
            }
            finally
            {
                Close((IChannel)doneQueue);
                Close((IChannel)publishQueue);
                Close(startQueue);
            }
        }
Beispiel #10
0
        public void Run()
        {
            IRawBodyUtility bodyUtil = new RawEncoderUtility();

            IInputChannel startQueue = null;
            IOutputChannel doneQueue = null;
            UInt64 batchSize = (UInt64)opts.pubTxSize;
            bool txPending = false;
            AmqpProperties amqpProperties = null;

            if (opts.durable)
            {
                amqpProperties = new AmqpProperties();
                amqpProperties.Durable = true;
            }

            try
            {
                publishQueue = QueueChannelFactory.CreateWriterChannel(this.destination, this.routingKey);
                doneQueue = QueueChannelFactory.CreateWriterChannel("", this.Fqn("pub_done"));
                startQueue = QueueChannelFactory.CreateReaderChannel(this.Fqn("pub_start"));

                // wait for our start signal
                Message msg;
                msg = startQueue.Receive(TimeSpan.MaxValue);
                Expect(bodyUtil.GetText(msg), "start");
                msg.Close();

                Stopwatch stopwatch = new Stopwatch();
                AsyncCallback sendCallback = new AsyncCallback(this.AsyncSendCB);

                byte[] data = new byte[this.msgSize];
                IAsyncResult sendResult = null;

                Console.WriteLine("sending {0}", this.msgCount);
                stopwatch.Start();

                if (batchSize > 0)
                {
                    Transaction.Current = new CommittableTransaction();
                }

                for (UInt64 i = 0; i < this.msgCount; i++)
                {
                    StampSequenceNo(data, i);
                    msg = bodyUtil.CreateMessage(data);
                    if (amqpProperties != null)
                    {
                        msg.Properties.Add("AmqpProperties", amqpProperties);
                    }

                    sendResult = publishQueue.BeginSend(msg, TimeSpan.MaxValue, sendCallback, msg);

                    if (batchSize > 0)
                    {
                        txPending = true;
                        if (((i + 1) % batchSize) == 0)
                        {
                            ((CommittableTransaction)Transaction.Current).Commit();
                            txPending = false;
                            Transaction.Current = new CommittableTransaction();
                        }
                    }
                }

                if (txPending)
                {
                    ((CommittableTransaction)Transaction.Current).Commit();
                }

                Transaction.Current = null;

                sendResult.AsyncWaitHandle.WaitOne();
                stopwatch.Stop();

                double mps = (msgCount / stopwatch.Elapsed.TotalSeconds);

                msg = bodyUtil.CreateMessage(String.Format("{0:0.##}", mps));
                doneQueue.Send(msg, TimeSpan.MaxValue);
                msg.Close();
            }
            finally
            {
                Close((IChannel)doneQueue);
                Close((IChannel)publishQueue);
                Close(startQueue);
            }
        }