示例#1
0
 internal Receiver(Client client, string name, string address)
 {
     this.Role = true;
     this.Name = name;
     this.client = client;
     this.lastDeliveryId = uint.MaxValue;
 }
示例#2
0
        static void Main(string[] args)
        {
            string address = "amqp://*****:*****@127.0.0.1:5672";
            if (args.Length > 0)
            {
                address = args[0];
            }

            // uncomment the following to write frame traces
            //Trace.TraceLevel = TraceLevel.Frame;
            //Trace.TraceListener = (f, a) => Console.WriteLine(DateTime.Now.ToString("[hh:ss.fff]") + " " + string.Format(f, a));

            Uri addressUri = new Uri(address);
            ContainerHost host = new ContainerHost(new Uri[] { addressUri }, null, addressUri.UserInfo);
            host.Open();
            Console.WriteLine("Container host is listening on {0}:{1}", addressUri.Host, addressUri.Port);

            host.RegisterLinkProcessor(new LinkProcessor());
            Console.WriteLine("Link processor is registered.");

            Console.WriteLine("Start the client");
            var client = new Client(address);
            var task = Task.Run(() => client.Run());

            Console.WriteLine("Press enter key to exist...");
            Console.ReadLine();

            client.Close();
            host.Close();
        }
示例#3
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();
        }
示例#4
0
 internal Sender(Client client, string name, string address)
 {
     this.Role = false;
     this.Name = name;
     this.client = client;
 }
示例#5
0
 static void client_OnError(Client client, Link link, Symbol error)
 {
     Microsoft.SPOT.Debug.Print((link != null ? "Link" : "Client") + " was closed due to error " + (error ?? "[unknown]"));
 }