本文整理汇总了C#中Amqp.ReceiverLink.Reject方法的典型用法代码示例。如果您正苦于以下问题:C# ReceiverLink.Reject方法的具体用法?C# ReceiverLink.Reject怎么用?C# ReceiverLink.Reject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amqp.ReceiverLink
的用法示例。
在下文中一共展示了ReceiverLink.Reject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例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);
}
示例3: TryHandleMessage
private void TryHandleMessage(ReceiverLink receiverLink, Message amqpMessage)
{
// NOTE this method _should not_ throw an exception!
var threadName = receiverLink.Name;
var messageID = amqpMessage.Properties?.MessageId ?? "?";
try
{
logger.Debug("{0}: Received Message with MessageId={1}", threadName, messageID);
var headers = new Dictionary<string, string>();
if (amqpMessage.ApplicationProperties != null)
{
foreach (var key in amqpMessage.ApplicationProperties.Map.Keys)
{
headers[key.ToString()] = amqpMessage.ApplicationProperties.Map[key].ToString();
}
}
object message = null;
try
{
message = DecodeMessage(amqpMessage);
}
catch (Exception e)
{
logger.Error(e, "{0}: Cannot Decode Message. Will not re-enqueue.", threadName);
OnPoisonMessageDetected(new PoisonMessageDetectedEventArgs()
{
QueueName = ReceiverLinkAddress,
Retries = MaxRetries,
Exception = e,
MessageId = messageID,
ErrorCode = "DecodeException",
});
}
if (message != null)
{
var transportMessage = new IncomingTransportMessage(messageID, headers, message);
Exception lastException = null;
if (faultManager.HasMaxRetriesExceeded(transportMessage, out lastException))
{
logger.Error(lastException, "{0}: MaxRetriesExceeded for MessageId={1}. Will not re-enqueue.", threadName, messageID.ToString());
OnPoisonMessageDetected(new PoisonMessageDetectedEventArgs()
{
QueueName = ReceiverLinkAddress,
Retries = MaxRetries,
Exception = lastException,
MessageId = messageID,
ErrorCode = "MaxRetriesExceeded",
});
}
else
{
logger.Debug("{0}: Notifying observers of new TransportMessage for MessageId={1}.", threadName, messageID.ToString());
OnMessageAvailable(transportMessage);
faultManager.ClearFailuresForMessage(messageID);
}
}
receiverLink.Accept(amqpMessage);
logger.Debug("{0}: Accepting MessageId={1}", threadName, messageID.ToString());
}
catch (Exception e)
{
faultManager.IncrementFailuresForMessage(messageID.ToString(), e);
receiverLink.Reject(amqpMessage);
logger.Error(e, "{0}: Exception caught handling MessageId={1}. Rejecting.", threadName, messageID.ToString());
Thread.Sleep(1000); // TODO possibly implement a backoff with the fault manager based on number of retries?
}
}