本文整理汇总了C#中Amqp.ReceiverLink.SetCredit方法的典型用法代码示例。如果您正苦于以下问题:C# ReceiverLink.SetCredit方法的具体用法?C# ReceiverLink.SetCredit怎么用?C# ReceiverLink.SetCredit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amqp.ReceiverLink
的用法示例。
在下文中一共展示了ReceiverLink.SetCredit方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: TestMethod_AdvancedLinkFlowControl
public void TestMethod_AdvancedLinkFlowControl()
{
string testName = "AdvancedLinkFlowControl";
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 };
sender.Send(message, null, null);
}
ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
receiver.SetCredit(2, false);
Message m1 = receiver.Receive();
Message m2 = receiver.Receive();
Assert.AreEqual("msg0", m1.Properties.MessageId);
Assert.AreEqual("msg1", m2.Properties.MessageId);
receiver.Accept(m1);
receiver.Accept(m2);
ReceiverLink receiver2 = new ReceiverLink(session, "receiver2-" + testName, testTarget.Path);
receiver2.SetCredit(2, false);
Message m3 = receiver2.Receive();
Message m4 = receiver2.Receive();
Assert.AreEqual("msg2", m3.Properties.MessageId);
Assert.AreEqual("msg3", m4.Properties.MessageId);
receiver2.Accept(m3);
receiver2.Accept(m4);
receiver.SetCredit(4);
for (int i = 4; i < nMsgs; i++)
{
Message m = receiver.Receive();
Assert.AreEqual("msg" + i, m.Properties.MessageId);
receiver.Accept(m);
}
sender.Close();
receiver.Close();
receiver2.Close();
session.Close();
connection.Close();
}
示例3: DuplicateLinkNameDifferentRoleTest
public void DuplicateLinkNameDifferentRoleTest()
{
string name = MethodInfo.GetCurrentMethod().Name;
this.host.RegisterLinkProcessor(new TestLinkProcessor());
string linkName = "same-link-for-different-role";
var connection = new Connection(Address);
var session1 = new Session(connection);
var sender = new SenderLink(session1, linkName, name);
sender.Send(new Message("msg1"), SendTimeout);
var session2 = new Session(connection);
var receiver = new ReceiverLink(session2, linkName, name);
receiver.SetCredit(2, false);
var message = receiver.Receive();
Assert.IsTrue(message != null, "No message was received");
receiver.Accept(message);
connection.Close();
}
示例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();
}
示例5: 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();
}