本文整理汇总了C#中BrokeredMessage.SafelyGetBodyTypeNameOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# BrokeredMessage.SafelyGetBodyTypeNameOrDefault方法的具体用法?C# BrokeredMessage.SafelyGetBodyTypeNameOrDefault怎么用?C# BrokeredMessage.SafelyGetBodyTypeNameOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BrokeredMessage
的用法示例。
在下文中一共展示了BrokeredMessage.SafelyGetBodyTypeNameOrDefault方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static MessageMetadata Create(BrokeredMessage message)
{
var typeFullName = message.SafelyGetBodyTypeNameOrDefault();
var shortMessageTypeName = typeFullName == null
? null
: typeFullName.Split('.').Last();
return new MessageMetadata(Guid.Parse(message.MessageId), Guid.Parse(message.CorrelationId), shortMessageTypeName, typeFullName);
}
示例2: GetBodyType
private Type GetBodyType(BrokeredMessage message)
{
var typeName = message.SafelyGetBodyTypeNameOrDefault();
var candidates = _messageTypes.Where(t => t.FullName == typeName).ToArray();
if (candidates.Any() == false)
throw new Exception($"The type '{typeName}' was not discovered by the type provider and cannot be loaded.");
return candidates.Single();
}
示例3: Dispatch
private async Task Dispatch(BrokeredMessage message)
{
// Early exit: have we pre-fetched this message and had our lock already expire? If so, just
// bail - it will already have been picked up by someone else.
if (message.LockedUntilUtc <= _clock.UtcNow)
{
GlobalMessageCounters.IncrementMessagesDroppedDueToExpiredLock(1);
_logger.Debug("Lock for message {MessageId} appears to have already expired so we're not dispatching it. Watch out for clock drift between your service bus server and {MachineName}!", message.MessageId, Environment.MachineName);
return;
}
try
{
Exception exception = null;
try
{
LogInfo("Dispatching", message);
using (_dispatchContextManager.StartNewDispatchContext(new SubsequentDispatchContext(message)))
{
await _taskFactory.StartNew(() => _messageDispatcher.Dispatch(message), TaskContext.Dispatch).Unwrap();
}
LogDebug("Dispatched", message);
LogDebug("Completing", message);
message.Properties[MessagePropertyKeys.DispatchComplete] = true;
await _taskFactory.StartNew(() => message.CompleteAsync(), TaskContext.CompleteOrAbandon).Unwrap();
LogInfo("Completed", message);
return;
}
catch (Exception exc)
{
if (exc is MessageLockLostException || (exc.InnerException is MessageLockLostException))
{
_logger.Error(exc,
"Message completion failed for {Type} from {QueuePath} [MessageId:{MessageId}, CorrelationId:{CorrelationId}]",
message.SafelyGetBodyTypeNameOrDefault(),
message.ReplyTo,
message.MessageId,
message.CorrelationId);
return;
}
_logger.Error(exc,
"Message dispatch failed for {Type} from {QueuePath} [MessageId:{MessageId}, CorrelationId:{CorrelationId}]",
message.SafelyGetBodyTypeNameOrDefault(),
message.ReplyTo,
message.MessageId,
message.CorrelationId);
exception = exc;
}
try
{
LogDebug("Abandoning", message);
message.Properties[MessagePropertyKeys.DispatchAbandoned] = true;
await message.AbandonAsync(exception.ExceptionDetailsAsProperties(_clock.UtcNow));
LogDebug("Abandoned", message);
}
catch (Exception exc)
{
_logger.Error(exc,
"Could not call Abandon() on message {Type} from {QueuePath} [MessageId:{MessageId}, CorrelationId:{CorrelationId}].",
message.SafelyGetBodyTypeNameOrDefault(),
message.MessageId,
message.CorrelationId,
message.ReplyTo);
}
}
catch (Exception exc)
{
_logger.Fatal(exc, "Unhandled exception in message pump");
}
}
示例4: LogInfo
private void LogInfo(string activity, BrokeredMessage message)
{
_logger.Info("{MessagePumpAction} message {Type} from {QueuePath} [MessageId:{MessageId}, CorrelationId:{CorrelationId}]",
activity,
message.SafelyGetBodyTypeNameOrDefault(),
message.ReplyTo,
message.MessageId,
message.CorrelationId);
}
示例5: Dispatch
private async Task Dispatch(BrokeredMessage message)
{
try
{
Exception exception = null;
try
{
LogInfo("Dispatching", message);
using (_dispatchContextManager.StartNewDispatchContext(new DispatchContext(message)))
{
await _messageDispatcher.Dispatch(message);
}
LogDebug("Dispatched", message);
LogDebug("Completing", message);
await message.CompleteAsync();
LogInfo("Completed", message);
return;
}
catch (Exception exc)
{
exception = exc;
}
_logger.Error(exception,
"Message dispatch failed for {0} from {1} [MessageId:{2}, CorrelationId:{3}]",
message.SafelyGetBodyTypeNameOrDefault(),
message.ReplyTo,
message.MessageId,
message.CorrelationId);
try
{
LogDebug("Abandoning", message);
await message.AbandonAsync(exception.ExceptionDetailsAsProperties(_clock.UtcNow));
LogDebug("Abandoned", message);
}
catch (Exception exc)
{
_logger.Error(exc,
"Could not call Abandon() on message {0} from {1} [MessageId:{2}, CorrelationId:{3}]. Possible lock expiry?",
message.SafelyGetBodyTypeNameOrDefault(),
message.MessageId,
message.CorrelationId,
message.ReplyTo);
}
}
catch (Exception exc)
{
_logger.Error(exc, "Unhandled exception in message pump");
}
}
示例6: GetBodyType
public Type GetBodyType(BrokeredMessage message)
{
var typeName = message.SafelyGetBodyTypeNameOrDefault();
var candidates = _typeProvider.AllMessageContractTypes().Where(t => t.FullName == typeName).ToArray();
if (candidates.Any() == false)
throw new Exception("The type '{0}' was not discovered by the type provider and cannot be loaded.".FormatWith(typeName));
// The TypeProvider should not provide a list of duplicates
return candidates.Single();
}