当前位置: 首页>>代码示例>>C#>>正文


C# ReceiverLink.Receive方法代码示例

本文整理汇总了C#中Amqp.ReceiverLink.Receive方法的典型用法代码示例。如果您正苦于以下问题:C# ReceiverLink.Receive方法的具体用法?C# ReceiverLink.Receive怎么用?C# ReceiverLink.Receive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amqp.ReceiverLink的用法示例。


在下文中一共展示了ReceiverLink.Receive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestMethod_BasicSendReceive

        public void TestMethod_BasicSendReceive()
        {
            string testName = "BasicSendReceive";
            const int nMsgs = 200;
            Connection connection = new Connection(testTarget.Address);
            Session session = new Session(connection);
            SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);

            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = new Message("msg" + i);
                message.Properties = new Properties() { GroupId = "abcdefg" };
                message.ApplicationProperties = new ApplicationProperties();
                message.ApplicationProperties["sn"] = i;
                sender.Send(message, null, null);
            }

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = receiver.Receive();
                Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.ApplicationProperties["sn"]);
                receiver.Accept(message);
            }
            
            sender.Close();
            receiver.Close();
            session.Close();
            connection.Close();
        }
开发者ID:Azure,项目名称:amqpnetlite,代码行数:30,代码来源:LinkTests.cs

示例2: Main

        static void Main(string[] args)
        {
            string brokerUrl = "amqp://localhost:5672";
              string address   = "my_queue";

              Address    brokerAddr = new Address(brokerUrl);
              Connection connection = new Connection(brokerAddr);
              Session    session    = new Session(connection);

              SenderLink   sender   = new   SenderLink(session, "sender",   address);
              ReceiverLink receiver = new ReceiverLink(session, "receiver", address);

              Message helloOut = new Message("Hello World!");
              sender.Send(helloOut);

              Message helloIn = receiver.Receive();
              receiver.Accept(helloIn);

              Console.WriteLine(helloIn.Body.ToString());

              receiver.Close();
              sender.Close();
              session.Close();
              connection.Close();
        }
开发者ID:ChugR,项目名称:amqp-blogs,代码行数:25,代码来源:HelloWorld.cs

示例3: Main

        //
        // Sample invocation: Interop.Drain.exe --broker localhost:5672 --timeout 30 --address my-queue
        //
        static int Main(string[] args)
        {
            const int ERROR_SUCCESS = 0;
            const int ERROR_NO_MESSAGE = 1;
            const int ERROR_OTHER = 2;

            int exitCode = ERROR_SUCCESS;
            Connection connection = null;
            try
            {
                Options options = new Options(args);

                Address address = new Address(options.Url);
                connection = new Connection(address);
                Session session = new Session(connection);
                ReceiverLink receiver = new ReceiverLink(session, "receiver-drain", options.Address);
                int timeout = int.MaxValue;
                if (!options.Forever)
                    timeout = 1000 * options.Timeout;
                Message message = new Message();
                int nReceived = 0;
                receiver.SetCredit(options.InitialCredit);
                while ((message = receiver.Receive(timeout)) != null)
                {
                    nReceived++;
                    if (!options.Quiet)
                    {
                        Console.WriteLine("Message(Properties={0}, ApplicationProperties={1}, Body={2}",
                                      message.Properties, message.ApplicationProperties, message.Body);
                    }
                    receiver.Accept(message);
                    if (options.Count > 0 && nReceived == options.Count)
                    {
                        break;
                    }
                }
                if (message == null)
                {
                    exitCode = ERROR_NO_MESSAGE;
                }
                receiver.Close();
                session.Close();
                connection.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception {0}.", e);
                if (null != connection)
                    connection.Close();
                exitCode = ERROR_OTHER;
            }
            return exitCode;
        }
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:56,代码来源:Interop.Drain.cs

示例4: GetPartitions

        protected void GetPartitions(Session session)
        {
            ReceiverLink receiverLink = null;
            SenderLink senderLink = null;

            try
            {
                // create a pair of links for request/response
                Trace.WriteLine(TraceLevel.Information, "Creating a request and a response link...");
                string clientNode = "client-temp-node";
                senderLink = new SenderLink(session, "mgmt-sender", "$management");
                receiverLink = new ReceiverLink(
                    session,
                    "mgmt-receiver",
                    new Attach()
                    {
                        Source = new Source() { Address = "$management" },
                        Target = new Target() { Address = clientNode }
                    },
                    null);

                var request = new Amqp.Message();
                request.Properties = new Properties() { MessageId = "request1", ReplyTo = clientNode };
                request.ApplicationProperties = new ApplicationProperties();
                request.ApplicationProperties["operation"] = "READ";
                request.ApplicationProperties["name"] = settings.EventHubName;
                request.ApplicationProperties["type"] = "com.microsoft:eventhub";
                senderLink.Send(request, null, null);

                var response = receiverLink.Receive(15000); // time out after 15 seconds
                if (response == null)
                {
                    throw new Exception("No get partitions response was received.");
                }

                receiverLink.Accept(response);

                Trace.WriteLine(TraceLevel.Information, "Partition info {0}", response.Body.ToString());
                var partitionStrings = (string[])((Map)response.Body)["partition_ids"];
                Trace.WriteLine(TraceLevel.Information, "Partitions {0}", string.Join(",", partitionStrings));
                this.partitions = new List<string>(partitionStrings);
            }
            catch (Exception x)
            {
                Trace.WriteLine(TraceLevel.Error, "Error retrieving partitions:\r\n{0}", x.ToString());
                throw x;
            }
            finally
            {
                if (receiverLink != null) receiverLink.Close();
                if (senderLink != null) senderLink.Close();
            }
        }
开发者ID:fredfourie,项目名称:Argonaut,代码行数:53,代码来源:EventHubClient.cs

示例5: GetPartitions

        static string[] GetPartitions()
        {
            Trace.WriteLine(TraceLevel.Information, "Retrieving partitions...");
            Trace.WriteLine(TraceLevel.Information, "Establishing a connection...");
            Address address = new Address(sbNamespace, 5671, keyName, keyValue);
            Connection connection = new Connection(address);

            Trace.WriteLine(TraceLevel.Information, "Creating a session...");
            Session session = new Session(connection);

            // create a pair of links for request/response
            Trace.WriteLine(TraceLevel.Information, "Creating a request and a response link...");
            string clientNode = "client-temp-node";
            SenderLink sender = new SenderLink(session, "mgmt-sender", "$management");
            ReceiverLink receiver = new ReceiverLink(
                session,
                "mgmt-receiver",
                new Attach()
                {
                    Source = new Source() { Address = "$management" },
                    Target = new Target() { Address = clientNode }
                },
                null);

            Message request = new Message();
            request.Properties = new Properties() { MessageId = "request1", ReplyTo = clientNode };
            request.ApplicationProperties = new ApplicationProperties();
            request.ApplicationProperties["operation"] = "READ";
            request.ApplicationProperties["name"] = entity;
            request.ApplicationProperties["type"] = "com.microsoft:eventhub";
            sender.Send(request, null, null);

            Message response = receiver.Receive();
            if (response == null)
            {
                throw new Exception("No response was received.");
            }

            receiver.Accept(response);
            receiver.Close();
            sender.Close();
            connection.Close();

            Trace.WriteLine(TraceLevel.Information, "Partition info {0}", response.Body.ToString());
            string[] partitions = (string[])((Map)response.Body)["partition_ids"];
            Trace.WriteLine(TraceLevel.Information, "Partitions {0}", string.Join(",", partitions));
            Trace.WriteLine(TraceLevel.Information, "");

            return partitions;
        }
开发者ID:timhermann,项目名称:amqpnetlite,代码行数:50,代码来源:Program.cs

示例6: ReceiveMessages

        static void ReceiveMessages(string node, int count, string sessionId)
        {
            Trace.WriteLine(TraceLevel.Information, "Establishing a connection...");
            Address address = new Address(sbNamespace, 5671, keyName, keyValue);
            Connection connection = new Connection(address);

            Trace.WriteLine(TraceLevel.Information, "Creating a session...");
            Session session = new Session(connection);

            Trace.WriteLine(TraceLevel.Information, "Accepting a message session '{0}'...", sessionId ?? "<any>");
            Map filters = new Map();
            filters.Add(new Symbol("com.microsoft:session-filter"), sessionId);

            ReceiverLink receiver = new ReceiverLink(
                session,
                "sessionful-receiver-link",
                new Source() { Address = node, FilterSet = filters },
                null);

            for (int i = 0; i < count; i++)
            {
                Message message = receiver.Receive(30000);
                if (message == null)
                {
                    break;
                }

                if (i == 0)
                {
                    Trace.WriteLine(TraceLevel.Information, "Received message from session '{0}'", message.Properties.GroupId);
                }

                receiver.Accept(message);
            }

            Trace.WriteLine(TraceLevel.Information, "Finished receiving. Shutting down...");
            Trace.WriteLine(TraceLevel.Information, "");

            receiver.Close();
            session.Close();
            connection.Close();
        }
开发者ID:timhermann,项目名称:amqpnetlite,代码行数:42,代码来源:Program.cs

示例7: GetPartitions

        string[] GetPartitions()
        {
            Address address = new Address(sbNamespace, 5671, ReckeyName, ReckeyValue);
            Connection connection = new Connection(address);
            Session session = new Session(connection);

            // create a pair of links for request/response
            string clientNode = "client-temp-node";
            SenderLink sender = new SenderLink(session, "mgmt-sender", "$management");
            ReceiverLink receiver = new ReceiverLink(
                session,
                "mgmt-receiver",
                new Attach()
                {
                    Source = new Source() { Address = "$management" },
                    Target = new Target() { Address = clientNode }
                },
                null);

            Message request = new Message();
            request.Properties = new Properties() { MessageId = "request1", ReplyTo = clientNode };
            request.ApplicationProperties = new ApplicationProperties();
            request.ApplicationProperties["operation"] = "READ";
            request.ApplicationProperties["name"] = entity;
            request.ApplicationProperties["type"] = "com.microsoft:eventhub";
            sender.Send(request, null, null);

            Message response = receiver.Receive();
            if (response == null)
            {
                throw new Exception("No response was received.");
            }
            receiver.Accept(response);
            receiver.Close();
            sender.Close();
            connection.Close();
            string[] partitions = (string[])((Map)response.Body)["partition_ids"];
            return partitions;
        }
开发者ID:mohamedemam0,项目名称:ReceivingData,代码行数:39,代码来源:MainPage.xaml.cs

示例8: TestMethod_ReceiveWaiter

        public void TestMethod_ReceiveWaiter()
        {
            string testName = "ReceiveWaiter";
            Connection connection = new Connection(testTarget.Address);
            Session session = new Session(connection);

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
            ManualResetEvent gotMessage = new ManualResetEvent(false);
            Fx.StartThread(() =>
            {
                Message message = receiver.Receive();
                if (message != null)
                {
                    Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.Properties.MessageId);
                    receiver.Accept(message);
                    gotMessage.Set();
                }
            });

            SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
            Message msg = new Message() { Properties = new Properties() { MessageId = "123456" } };
            sender.Send(msg, null, null);

            Assert.IsTrue(gotMessage.WaitOne(5000), "No message was received");

            sender.Close();
            receiver.Close();
            session.Close();
            connection.Close();
        }
开发者ID:Azure,项目名称:amqpnetlite,代码行数:30,代码来源:LinkTests.cs

示例9: ReceiveMessages

        // This function is the core receive function
        void ReceiveMessages(string scenario, int count, string filter, string partition,ReceivedData callback)
        {
            Trace.WriteLine(Amqp.TraceLevel.Information, "Running scenario '{0}', filter '{1}'...", scenario, filter);

            Trace.WriteLine(Amqp.TraceLevel.Information, "Establishing a connection...");
            Address address = new Address(sbNamespace, PORT, keyName, keyValue);
            Connection connection = new Connection(address);

            Trace.WriteLine(Amqp.TraceLevel.Information, "Creating a session...");
            Session session = new Session(connection);

            Trace.WriteLine(Amqp.TraceLevel.Information, "Creating a receiver link on partition {0}...", partition);
            string partitionAddress = entity + "/ConsumerGroups/$default/Partitions/" + partition;
            // Form the filter for receiving message based on the time stamp 
            Map filters = new Map();
            if (filter != null)
            {
                filters.Add(new Amqp.Types.Symbol("apache.org:selector-filter:string"),
                    new DescribedValue(new Amqp.Types.Symbol("apache.org:selector-filter:string"), filter));
            }

            string lastOffset = "-1";
            long lastSeqNumber = -1;
            DateTime lastEnqueueTime = DateTime.MinValue;

            ReceiverLink receiver = new ReceiverLink(
                session,
                "receiver-" + partition,
                new Source() { Address = partitionAddress, FilterSet = filters },
                null);
            // loop runs until clean up is called
            for (; g_bThreadActive; )
            {
                Message message = receiver.Receive(5000);
                if (message == null)
                {
                    continue;
                }

                receiver.Accept(message);
                Data data = (Data)message.BodySection;
                // Get the data such as offset, Seq number and Devicename from the response header
                lastOffset = (string)message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-offset")];
                lastSeqNumber = (long)message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-sequence-number")];
                lastEnqueueTime = (DateTime)message.MessageAnnotations[new Amqp.Types.Symbol("x-opt-enqueued-time")];
               
                var DeviceName = (string)message.MessageAnnotations[new Amqp.Types.Symbol("iothub-connection-device-id")];
                callback(data.Binary, DeviceName);
            }

            receiver.Close();
            session.Close();
            connection.Close();

        }
开发者ID:RVinoth,项目名称:UWPAzureIoTHubSDK,代码行数:56,代码来源:UWPIoTHubSDK.cs

示例10: TestMethod_SendAck

        public void TestMethod_SendAck()
        {
            string testName = "SendAck";
            const int nMsgs = 20;
            Connection connection = new Connection(testTarget.Address);
            Session session = new Session(connection);

            SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
            ManualResetEvent done = new ManualResetEvent(false);
            OutcomeCallback callback = (m, o, s) =>
            {
                Trace.WriteLine(TraceLevel.Verbose, "send complete: sn {0} outcome {1}", m.ApplicationProperties["sn"], o.Descriptor.Name);
                if ((int)m.ApplicationProperties["sn"] == (nMsgs - 1))
                {
                    done.Set();
                }
            };

            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = new Message();
                message.Properties = new Properties() { MessageId = "msg" + i, GroupId = testName };
                message.ApplicationProperties = new ApplicationProperties();
                message.ApplicationProperties["sn"] = i;
                sender.Send(message, callback, null);
            }

            done.WaitOne(10000);

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = receiver.Receive();
                Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.ApplicationProperties["sn"]);
                receiver.Accept(message);
            }
            
            sender.Close();
            receiver.Close();
            session.Close();
            connection.Close();
        }
开发者ID:Azure,项目名称:amqpnetlite,代码行数:42,代码来源:LinkTests.cs

示例11: TestMethod_MessageId

        public void TestMethod_MessageId()
        {
            string testName = "MessageId";
            Connection connection = new Connection(testTarget.Address);
            Session session = new Session(connection);
            object[] idList = new object[] { null, "string-id", 20000UL, Guid.NewGuid(), Encoding.UTF8.GetBytes("binary-id") };

            SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
            for (int i = 0; i < idList.Length; ++i)
            {
                Message message = new Message() { Properties = new Properties() };
                message.Properties.SetMessageId(idList[i]);
                message.Properties.SetCorrelationId(idList[(i + 2) % idList.Length]);
                sender.Send(message, null, null);
            }

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
            for (int i = 0; i < idList.Length; ++i)
            {
                Message message = receiver.Receive();
                receiver.Accept(message);
                Assert.AreEqual(idList[i], message.Properties.GetMessageId());
                Assert.AreEqual(idList[(i + 2) % idList.Length], message.Properties.GetCorrelationId());
            }

            connection.Close();

            // invalid types
            Properties prop = new Properties();
            try
            {
                prop.SetMessageId(0);
                Assert.IsTrue(false, "not a valid identifier type");
            }
            catch (AmqpException ae)
            {
                Assert.AreEqual(ErrorCode.NotAllowed, (string)ae.Error.Condition);
            }

            try
            {
                prop.SetCorrelationId(new Symbol("symbol"));
                Assert.IsTrue(false, "not a valid identifier type");
            }
            catch (AmqpException ae)
            {
                Assert.AreEqual(ErrorCode.NotAllowed, (string)ae.Error.Condition);
            }
        }
开发者ID:Azure,项目名称:amqpnetlite,代码行数:49,代码来源:LinkTests.cs

示例12: TestMethod_CloseBusyReceiver

        public void TestMethod_CloseBusyReceiver()
        {
            string testName = "CloseBusyReceiver";
            const int nMsgs = 20;
            Connection connection = new Connection(testTarget.Address);
            Session session = new Session(connection);

            SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = new Message();
                message.Properties = new Properties() { MessageId = "msg" + i };
                message.ApplicationProperties = new ApplicationProperties();
                message.ApplicationProperties["sn"] = i;
                sender.Send(message, null, null);
            }

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
            ManualResetEvent closed = new ManualResetEvent(false);
            receiver.Closed += (o, e) => closed.Set();
            receiver.Start(
                nMsgs,
                (r, m) =>
                {
                    if (m.Properties.MessageId == "msg0") r.Close(0);
                });
            Assert.IsTrue(closed.WaitOne(10000));

            ReceiverLink receiver2 = new ReceiverLink(session, "receiver2-" + testName, testTarget.Path);
            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = receiver2.Receive();
                Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.Properties.MessageId);
                receiver2.Accept(message);
            }

            receiver2.Close();
            sender.Close();
            session.Close();
            connection.Close();
        }
开发者ID:Azure,项目名称:amqpnetlite,代码行数:41,代码来源:LinkTests.cs

示例13: TestMethod_ReleaseMessage

        public void TestMethod_ReleaseMessage()
        {
            string testName = "ReleaseMessage";
            const int nMsgs = 20;
            Connection connection = new Connection(testTarget.Address);
            Session session = new Session(connection);

            SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = new Message();
                message.Properties = new Properties() { MessageId = "msg" + i };
                message.ApplicationProperties = new ApplicationProperties();
                message.ApplicationProperties["sn"] = i;
                sender.Send(message, null, null);
            }

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = receiver.Receive();
                Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.Properties.MessageId);
                if (i % 2 == 0)
                {
                    receiver.Accept(message);
                }
                else
                {
                    receiver.Release(message);
                }
            }
            receiver.Close();

            ReceiverLink receiver2 = new ReceiverLink(session, "receiver2-" + testName, testTarget.Path);
            for (int i = 0; i < nMsgs / 2; ++i)
            {
                Message message = receiver2.Receive();
                Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.Properties.MessageId);
                receiver2.Accept(message);
            }

            receiver2.Close();
            sender.Close();
            session.Close();
            connection.Close();
        }
开发者ID:Azure,项目名称:amqpnetlite,代码行数:46,代码来源:LinkTests.cs

示例14: TestMethod_LinkReopen

        public void TestMethod_LinkReopen()
        {
            string testName = "LinkReopen";

            Connection connection = new Connection(testTarget.Address);
            Session session = new Session(connection);
            SenderLink sender = new SenderLink(session, "sender", testTarget.Path);
            sender.Send(new Message("test") { Properties = new Properties() { MessageId = testName } });
            sender.Close();

            sender = new SenderLink(session, "sender", testTarget.Path);
            sender.Send(new Message("test2") { Properties = new Properties() { MessageId = testName } });
            sender.Close();

            ReceiverLink receiver = new ReceiverLink(session, "receiver", testTarget.Path);
            for (int i = 1; i <= 2; i++)
            {
                var m = receiver.Receive();
                Assert.IsTrue(m != null, "Didn't receive message " + i);
                receiver.Accept(m);
            }

            session.Close(0);
            connection.Close();
            Assert.IsTrue(connection.Error == null, "connection has error!");
        }
开发者ID:Azure,项目名称:amqpnetlite,代码行数:26,代码来源:LinkTests.cs

示例15: RunRequestClient

        static void RunRequestClient(string address)
        {
            Connection connection = new Connection(new Address(address));
            Session session = new Session(connection);

            string replyTo = "client-reply-to";
            Attach recvAttach = new Attach()
            {
                Source = new Source() { Address = "request_processor" },
                Target = new Target() { Address = replyTo }
            };

            ReceiverLink receiver = new ReceiverLink(session, "request-client-receiver", recvAttach, null);
            SenderLink sender = new SenderLink(session, "request-client-sender", "request_processor");

            Message request = new Message("hello");
            request.Properties = new Properties() { MessageId = "request1", ReplyTo = replyTo };
            sender.Send(request, null, null);
            Console.WriteLine("Sent request {0} body {1}", request.Properties, request.Body);

            Message response = receiver.Receive();
            Console.WriteLine("Received response: {0} body {1}", response.Properties, response.Body);
            receiver.Accept(response);

            receiver.Close();
            sender.Close();
            session.Close();
            connection.Close();
        }
开发者ID:helljai,项目名称:amqpnetlite,代码行数:29,代码来源:Program.cs


注:本文中的Amqp.ReceiverLink.Receive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。