本文整理汇总了C#中Rebus.Messages.TransportMessage.GetMessageLabel方法的典型用法代码示例。如果您正苦于以下问题:C# TransportMessage.GetMessageLabel方法的具体用法?C# TransportMessage.GetMessageLabel怎么用?C# TransportMessage.GetMessageLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rebus.Messages.TransportMessage
的用法示例。
在下文中一共展示了TransportMessage.GetMessageLabel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
public async Task<Message> Deserialize(TransportMessage transportMessage)
{
string contentEncoding;
if (!transportMessage.Headers.TryGetValue(Headers.ContentEncoding, out contentEncoding))
{
return await _serializer.Deserialize(transportMessage);
}
if (contentEncoding != GzipEncodingHeader)
{
var message = $"The message {transportMessage.GetMessageLabel()} has a '{Headers.ContentEncoding}' with the" +
$" value '{contentEncoding}', but this serializer decorator only knows how to decompress" +
$" '{GzipEncodingHeader}'";
throw new ArgumentException(message);
}
var headers = transportMessage.Headers.Clone();
var compressedBody = transportMessage.Body;
headers.Remove(Headers.ContentEncoding);
var uncompressedBody = _zipper.Unzip(compressedBody);
var uncompressedTransportMessage = new TransportMessage(headers, uncompressedBody);
return await _serializer.Deserialize(uncompressedTransportMessage);
}
示例2: HandleMessage
public void HandleMessage(TransportMessage transportMessage, ITransactionContext transactionContext)
{
var message = transportMessage.GetMessageLabel();
var options = new List<KeyOption>();
if (DefaultOutputQueue != null)
{
options.Add(KeyOption.New('d',
() => { MoveMessage(transportMessage, transactionContext, DefaultOutputQueue); },
"Move to default queue '{0}'", DefaultOutputQueue));
}
if (transportMessage.Headers.ContainsKey(Headers.SourceQueue))
{
var sourceQueue = transportMessage.Headers[Headers.SourceQueue];
options.Add(KeyOption.New('s',
() => { MoveMessage(transportMessage, transactionContext, sourceQueue); },
"Return to source queue '{0}'", sourceQueue));
}
options.Add(KeyOption.New('c', () =>
{
Console.Write("queue > ");
var queueName = Console.ReadLine();
MoveMessage(transportMessage, transactionContext, queueName);
}, "Enter custom queue name to move message to"));
Prompt(message, options);
Text.PrintLine();
}
示例3: CreateBrokeredMessage
public static BrokeredMessage CreateBrokeredMessage(TransportMessage message)
{
var headers = message.Headers.Clone();
var brokeredMessage = new BrokeredMessage(new MemoryStream(message.Body), true);
string timeToBeReceivedStr;
if (headers.TryGetValue(Headers.TimeToBeReceived, out timeToBeReceivedStr))
{
timeToBeReceivedStr = headers[Headers.TimeToBeReceived];
var timeToBeReceived = TimeSpan.Parse(timeToBeReceivedStr);
brokeredMessage.TimeToLive = timeToBeReceived;
}
string deferUntilTime;
if (headers.TryGetValue(Headers.DeferredUntil, out deferUntilTime))
{
var deferUntilDateTimeOffset = deferUntilTime.ToDateTimeOffset();
brokeredMessage.ScheduledEnqueueTimeUtc = deferUntilDateTimeOffset.UtcDateTime;
headers.Remove(Headers.DeferredUntil);
}
string contentType;
if (headers.TryGetValue(Headers.ContentType, out contentType))
{
brokeredMessage.ContentType = contentType;
}
string correlationId;
if (headers.TryGetValue(Headers.CorrelationId, out correlationId))
{
brokeredMessage.CorrelationId = correlationId;
}
brokeredMessage.Label = message.GetMessageLabel();
foreach (var kvp in headers)
{
brokeredMessage.Properties[kvp.Key] = PossiblyLimitLength(kvp.Value);
}
return brokeredMessage;
}
示例4: ForwardMessageToExternalTimeoutManager
async Task ForwardMessageToExternalTimeoutManager(TransportMessage transportMessage, ITransactionContext transactionContext)
{
var timeoutManagerAddress = _options.ExternalTimeoutManagerAddressOrNull;
_log.Info("Forwarding deferred message {0} to external timeout manager '{1}'",
transportMessage.GetMessageLabel(), timeoutManagerAddress);
await _transport.Send(timeoutManagerAddress, transportMessage, transactionContext);
}
示例5: GetMessageLabel
static string GetMessageLabel(TransportMessage message)
{
try
{
return message.GetMessageLabel();
}
catch
{
// if that failed, it's most likely because we're running in legacy mode - therefore:
return message.Headers.GetValueOrNull(Headers.MessageId)
?? message.Headers.GetValueOrNull("rebus-msg-id")
?? "<unknown ID>";
}
}
示例6: ProcessMessage
async Task ProcessMessage(TransactionContext context, TransportMessage transportMessage)
{
try
{
context.Items["OwningBus"] = _owningBus;
AmbientTransactionContext.SetCurrent(context);
var incomingSteps = _pipeline.ReceivePipeline();
var stepContext = new IncomingStepContext(transportMessage, context);
await _pipelineInvoker.Invoke(stepContext, incomingSteps);
try
{
await context.Complete();
}
catch (Exception exception)
{
_log.Error(exception, "An error occurred when attempting to complete the transaction context");
}
}
catch (ThreadAbortException exception)
{
context.Abort();
_log.Error(exception, $"Worker was killed while handling message {transportMessage.GetMessageLabel()}");
}
catch (Exception exception)
{
context.Abort();
_log.Error(exception, $"Unhandled exception while handling message {transportMessage.GetMessageLabel()}");
}
finally
{
AmbientTransactionContext.SetCurrent(null);
}
}
示例7: CreateBrokeredMessage
static BrokeredMessage CreateBrokeredMessage(TransportMessage message)
{
var headers = message.Headers;
var brokeredMessage = new BrokeredMessage(new MemoryStream(message.Body), true);
foreach (var kvp in headers)
{
brokeredMessage.Properties[kvp.Key] = PossiblyLimitLength(kvp.Value);
}
if (headers.ContainsKey(Headers.TimeToBeReceived))
{
var timeToBeReceivedStr = headers[Headers.TimeToBeReceived];
var timeToBeReceived = TimeSpan.Parse(timeToBeReceivedStr);
brokeredMessage.TimeToLive = timeToBeReceived;
}
string contentType;
if (headers.TryGetValue(Headers.ContentType, out contentType))
{
brokeredMessage.ContentType = contentType;
}
string correlationId;
if (headers.TryGetValue(Headers.CorrelationId, out correlationId))
{
brokeredMessage.CorrelationId = correlationId;
}
brokeredMessage.Label = message.GetMessageLabel();
return brokeredMessage;
}