本文整理汇总了C#中BrokeredMessage.DeadLetter方法的典型用法代码示例。如果您正苦于以下问题:C# BrokeredMessage.DeadLetter方法的具体用法?C# BrokeredMessage.DeadLetter怎么用?C# BrokeredMessage.DeadLetter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BrokeredMessage
的用法示例。
在下文中一共展示了BrokeredMessage.DeadLetter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnBrokerMessage
private void OnBrokerMessage(BrokeredMessage brokeredMessage)
{
try
{
//Ignore messages from self
if (brokeredMessage.Properties[SidAttributeName].ToString() == _sid)
{
brokeredMessage.Complete();
return;
}
var json = brokeredMessage.Properties[DataAttributeName].ToString();
var message = _jsonSerializer.DeserializeFromString<Message>(json);
var pipeline = Composable.GetExport<IXSocketPipeline>();
var controller = Composable.GetExports<IXSocketController>().First(p => p.Alias == message.Controller);
controller.ProtocolInstance = new XSocketInternalProtocol();
pipeline.OnIncomingMessage(controller, message);
brokeredMessage.Complete();
}
catch (Exception ex)
{
Composable.GetExport<IXLogger>().Error(ex.ToString());
// Indicates a problem
if (brokeredMessage.DeliveryCount > 3)
{
brokeredMessage.DeadLetter();
}
else
{
brokeredMessage.Abandon();
}
}
}
示例2: OnMessageReceived
private void OnMessageReceived( BrokeredMessage message )
{
object payload;
using ( var stream = message.GetBody<Stream>() )
using ( var reader = new StreamReader( stream ) )
{
try
{
payload = this.serializer.Deserialize( reader );
}
catch ( SerializationException e )
{
message.DeadLetter( e.Message, e.ToString() );
return;
}
}
ProcessMessage( payload, message.MessageId, message.CorrelationId );
message.Complete();
}
示例3: OnMessage
private void OnMessage(BrokeredMessage message)
{
try
{
if (OnMessageReceived != null)
{
var headers = ResolveMessageHeaders(message);
var bodyStream = message.GetBody<Stream>();
var channelMessage = new ChannelMessage(bodyStream);
channelMessage.AddHeader(headers);
OnMessageReceived(this, new MessageReceivedEventArgs { Message = channelMessage });
}
message.Complete();
}
catch (Exception ex)
{
message.DeadLetter();
throw;
}
}
示例4: OnBrokerMessage
private void OnBrokerMessage(BrokeredMessage message)
{
try
{
Composable.GetExport<IXLogger>().Debug("Message Arrived {@m}", message);
var m = this.Serializer.DeserializeFromString<Message>(message.Properties["JSON"].ToString());
var pipe = Composable.GetExport<IXSocketPipeline>();
var ctrl = Composable.GetExports<IXSocketController>().First(p => p.Alias == m.Controller);
ctrl.ProtocolInstance = new XSocketInternalProtocol();
pipe.OnIncomingMessage(ctrl, m);
message.Complete();
}
catch (Exception)
{
// Indicates a problem, unlock message in subscription
if (message.DeliveryCount > 3)
message.DeadLetter();
else
message.Abandon();
}
}
示例5: SafeDeadLetter
static bool SafeDeadLetter(BrokeredMessage msg, string reason) {
try {
// Mark brokered message as complete.
msg.DeadLetter(reason, "Max retries Exceeded.");
// Return a result indicating that the message has been completed successfully.
return true;
}
catch (MessageLockLostException) {
// It's too late to compensate the loss of a message lock. We should just ignore it so that it does not break the receive loop.
// We should be prepared to receive the same message again.
}
catch (MessagingException) {
// There is nothing we can do as the connection may have been lost, or the underlying topic/subscription may have been removed.
// If Complete() fails with this exception, the only recourse is to prepare to receive another message (possibly the same one).
}
return false;
}
示例6: Handle
private async Task Handle(BrokeredMessage brokeredMessage)
{
dynamic innerMessage = JsonConvert.DeserializeObject(brokeredMessage.GetBody<string>(),
new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All,
DateFormatHandling = DateFormatHandling.IsoDateFormat
}) as IMessage;
try
{
await _dispatcher.Handle(innerMessage);
await brokeredMessage.CompleteAsync();
}
catch (Exception exception)
{
if (brokeredMessage.DeliveryCount >= 5)
{
brokeredMessage.DeadLetter(exception.GetBaseException().Message, exception.GetBaseException().ToString());
}
brokeredMessage.Abandon();
}
}