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


C# ReceiverLink.Release方法代码示例

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


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

示例1: 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

示例2: ContainerHostSourceLinkEndpointTest

        public void ContainerHostSourceLinkEndpointTest()
        {
            string name = MethodInfo.GetCurrentMethod().Name;
            int count = 100;
            Queue<Message> messages = new Queue<Message>();
            for (int i = 0; i < count; i++)
            {
                messages.Enqueue(new Message("test") { Properties = new Properties() { MessageId = name + i } });
            }

            var source = new TestMessageSource(messages);
            this.host.RegisterLinkProcessor(new TestLinkProcessor(link => new SourceLinkEndpoint(source, link)));

            var connection = new Connection(Address);
            var session = new Session(connection);
            var receiver = new ReceiverLink(session, "receiver0", name);
            int released = 0;
            int rejected = 0;
            for (int i = 1; i <= count; i++)
            {
                Message message = receiver.Receive();
                if (i % 5 == 0)
                {
                    receiver.Reject(message);
                    rejected++;
                }
                else if (i % 17 == 0)
                {
                    receiver.Release(message);
                    released++;
                }
                else
                {
                    receiver.Accept(message);
                }
            }

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

            Assert.AreEqual(released, messages.Count);
            Assert.AreEqual(rejected, source.DeadletterMessage.Count);
        }
开发者ID:yonglehou,项目名称:amqpnetlite,代码行数:44,代码来源:ContainerHostTests.cs

示例3: TransactedRetiringAndPosting

        public void TransactedRetiringAndPosting()
        {
            string testName = "TransactedRetiringAndPosting";
            int nMsgs = 10;

            Connection connection = new Connection(this.address);
            Session session = new Session(connection);
            SenderLink sender = new SenderLink(session, "sender-" + testName, "q1");

            for (int i = 0; i < nMsgs; i++)
            {
                Message message = new Message("test");
                message.Properties = new Properties() { MessageId = "msg" + i, GroupId = testName };
                sender.Send(message);
            }

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, "q1");

            receiver.SetCredit(2, false);
            Message message1 = receiver.Receive();
            Message message2 = receiver.Receive();

            // ack message1 and send a new message in a txn
            using (var ts = new TransactionScope())
            {
                receiver.Accept(message1);

                Message message = new Message("test");
                message.Properties = new Properties() { MessageId = "msg" + nMsgs, GroupId = testName };
                sender.Send(message);

                ts.Complete();
            }

            // ack message2 and send a new message in a txn but abort the txn
            using (var ts = new TransactionScope())
            {
                receiver.Accept(message2);

                Message message = new Message("test");
                message.Properties = new Properties() { MessageId = "msg" + (nMsgs + 1), GroupId = testName };
                sender.Send(message1);
            }

            receiver.Release(message2);

            // receive all messages. should see the effect of the first txn
            receiver.SetCredit(nMsgs, false);
            for (int i = 1; i <= nMsgs; i++)
            {
                Message message = receiver.Receive();
                Trace.WriteLine(TraceLevel.Information, "receive: {0}", message.Properties.MessageId);
                receiver.Accept(message);
                Assert.AreEqual("msg" + i, message.Properties.MessageId);
            }

            connection.Close();
        }
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:58,代码来源:TransactionTests.cs

示例4: Main

        public static void Main(string[] args)
        {
            Trace.TraceLevel = TraceLevel.Frame;
            Trace.TraceListener = (f, a) =>
            {
                var t = DateTime.Now.ToString("[hh:ss.fff]") + " " + string.Format(f, a);
                Console.WriteLine(t);
            };

            connection = new Connection(amqpAddress, null, new Open()
            {
                ContainerId = Guid.NewGuid().ToString(),
                ChannelMax = 64,
                MaxFrameSize = 200,
            }, null);
            connection.Closed = OnClosed;

            session = new Session(connection);
            session.Closed = OnClosed;

            var linkName = Guid.NewGuid().ToString();
            senderLink = new SenderLink(session, linkName, new Attach()
            {
                Target = new Target()
                {
                    Address = "TestQueue1",
                },
                //RcvSettleMode = ReceiverSettleMode.Second,
                //SndSettleMode = SenderSettleMode.Settled,
            }, null);
            senderLink.Closed = OnClosed;

            for (int i = 0; i < 10; i++)
            {
                senderLink.Send(CreateMessage(), 5000);
            }

            senderLink.Close();

            linkName = Guid.NewGuid().ToString();
            receiverLink = new ReceiverLink(session, linkName, "TestQueue1");
            receiverLink.Closed = OnClosed;
            receiverLink.SetCredit(1);
            var message = receiverLink.Receive(20000);
            int receiveCount = 0;
            while(message != null)
            {
                receiveCount++;
                //Console.WriteLine(message.Body.GetType());
                Console.WriteLine(message.BodySection.GetType());
                Console.WriteLine("Receive #{0}. Message = \"{1}\"", receiveCount.ToString(), Encoding.UTF8.GetString(message.GetBody<byte[]>()));
                if (receiveCount % 7 == 0)
                    receiverLink.Release(message);
                else if (receiveCount % 4 == 0)
                    receiverLink.Reject(message);
                else
                    receiverLink.Accept(message);
                Thread.Sleep(10000);
                message = receiverLink.Receive(20000);
            }
            receiverLink.Close();

            session.Close();
            connection.Close();
        }
开发者ID:jdaigle,项目名称:LightRail,代码行数:65,代码来源:Program.cs

示例5: TransactedRetiring

        public void TransactedRetiring()
        {
            string testName = "TransactedRetiring";
            int nMsgs = 10;

            Connection connection = new Connection(this.address);
            Session session = new Session(connection);
            SenderLink sender = new SenderLink(session, "sender-" + testName, "q1");

            // send one extra for validation
            for (int i = 0; i < nMsgs + 1; i++)
            {
                Message message = new Message("test");
                message.Properties = new Properties() { MessageId = "msg" + i, GroupId = testName };
                sender.Send(message);
            }

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, "q1");
            Message[] messages = new Message[nMsgs];
            for (int i = 0; i < nMsgs; i++)
            {
                messages[i] = receiver.Receive();
                Trace.WriteLine(TraceLevel.Information, "receive: {0}", messages[i].Properties.MessageId);
            }

            // commit harf
            using (var ts = new TransactionScope())
            {
                for (int i = 0; i < nMsgs / 2; i++)
                {
                    receiver.Accept(messages[i]);
                }

                ts.Complete();
            }

            // rollback
            using (var ts = new TransactionScope())
            {
                for (int i = nMsgs / 2; i < nMsgs; i++)
                {
                    receiver.Accept(messages[i]);
                }
            }

            // after rollback, messages should be still acquired
            {
                Message message = receiver.Receive();
                Assert.AreEqual("msg" + nMsgs, message.Properties.MessageId);
                receiver.Release(message);
            }

            // commit
            using (var ts = new TransactionScope())
            {
                for (int i = nMsgs / 2; i < nMsgs; i++)
                {
                    receiver.Accept(messages[i]);
                }

                ts.Complete();
            }

            // only the last message is left
            {
                Message message = receiver.Receive();
                Assert.AreEqual("msg" + nMsgs, message.Properties.MessageId);
                receiver.Accept(message);
            }

            // at this point, the queue should have zero messages.
            // If there are messages, it is a bug in the broker.

            connection.Close();
        }
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:75,代码来源:TransactionTests.cs


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