Exemple #1
0
        static void Main(string[] args)
        {
            try
            {
                PerfArguments perfArgs = new PerfArguments(args);
                if (args.Length == 0 || Arguments.IsHelp(perfArgs.Operation))
                {
                    Usage();
                    return;
                }

                if (perfArgs.TraceLevel != 0)
                {
                    Trace.TraceLevel = perfArgs.TraceLevel;
                    Trace.TraceListener = (f, o) => Console.WriteLine(DateTime.Now.ToString("[hh:mm:ss.fff]") + " " + string.Format(f, o));
                }

                Role role;
                if (string.Equals("send", perfArgs.Operation, StringComparison.OrdinalIgnoreCase))
                {
                    role = new Sender(perfArgs);
                }
                else if (string.Equals("receive", perfArgs.Operation, StringComparison.OrdinalIgnoreCase))
                {
                    role = new Receiver(perfArgs);
                }
                else if (string.Equals("request", perfArgs.Operation, StringComparison.OrdinalIgnoreCase))
                {
                    role = new Requestor(perfArgs);
                }
                else if (string.Equals("reply", perfArgs.Operation, StringComparison.OrdinalIgnoreCase))
                {
                    role = new ReplyListener(perfArgs);
                }
                else if (string.Equals("listen", perfArgs.Operation, StringComparison.OrdinalIgnoreCase))
                {
                    role = new Listener(perfArgs);
                }
                else
                {
                    throw new ArgumentException(perfArgs.Operation);
                }

                Console.WriteLine("Running perf test...");
                role.Run();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Exemple #2
0
        static void Send()
        {
            const int nMsgs = 50;

            // Map IotHub settings to AMQP protocol settings
            string hostName = iotHubName + ".azure-devices.net";
            int port = 5671;
            string userName = iotUser + "@sas.root." + iotHubName;
            string password = sasToken;
            string senderAddress = "devices/" + device + "/messages/events";
            string receiverAddress = "devices/" + device + "/messages/deviceBound";

            Client client = new Client();
            client.OnError += client_OnError;
            client.Connect(hostName, port, true, userName, password);

            int count = 0;
            ManualResetEvent done = new ManualResetEvent(false);
            Receiver receiver = client.CreateReceiver(receiverAddress);
            receiver.Start(20, (r, m) =>
            {
                r.Accept(m);
                if (++count >= nMsgs) done.Set();
            });

            Thread.Sleep(1000);
            
            Sender[] senders = new Sender[5];
            for (int i = 0; i < senders.Length; i++)
            {
                senders[i] = client.CreateSender(senderAddress);
            }

            for (int i = 0; i < nMsgs; i++)
            {
                senders[i % senders.Length].Send(new Message() { Body = Guid.NewGuid().ToString() });
            }

            done.WaitOne(120000, false);

            client.Close();
        }
Exemple #3
0
        internal uint Send(Sender sender, Message message, bool settled)
        {
            ByteBuffer buffer = new ByteBuffer(128, true);
            buffer.AdjustPosition(TransferFramePrefixSize, 0);   // reserve space for frame header and transfer
            message.Encode(buffer);

            while (buffer.Length > 0)
            {
                this.Wait(o => ((Client)o).outWindow == 0, this, 60000);
                lock (this)
                {
                    this.nextOutgoingId++;
                    if (this.outWindow < uint.MaxValue)
                    {
                        this.outWindow--;
                    }
                }

                int payload = this.WriteTransferFrame(sender.Handle, this.deliveryId, settled, buffer, this.maxFrameSize);
                Fx.DebugPrint(true, 0, "transfer", new List { this.deliveryId, settled, payload }, "delivery-id", "settled", "payload");
            }

            return this.deliveryId++;
        }
Exemple #4
0
 /// <summary>
 /// Creates a Sender from the client.
 /// </summary>
 /// <param name="address">The address of the node where messages are sent.</param>
 /// <returns>A Sender object.</returns>
 public Sender CreateSender(string address)
 {
     Fx.AssertAndThrow(ErrorCode.ClientNotConnected, this.state > 0 && this.state < 0xff);
     var sender = new Sender(this, Client.Name + "-sender" + Interlocked.Increment(ref linkId), address);
     lock (this)
     {
         this.AddLink(sender, false, null, address);
         return sender;
     }
 }