本文整理汇总了C#中BrokeredMessage.GetBody方法的典型用法代码示例。如果您正苦于以下问题:C# BrokeredMessage.GetBody方法的具体用法?C# BrokeredMessage.GetBody怎么用?C# BrokeredMessage.GetBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BrokeredMessage
的用法示例。
在下文中一共展示了BrokeredMessage.GetBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMessagePayload
private static string GetMessagePayload(BrokeredMessage message)
{
string ret = string.Empty;
//try
//{
// var o = message.GetBody<System.IO.Stream>();
// using (var r = new StreamReader(o))
// {
// ret = r.ReadToEnd();
// }
//}
//catch
//{
// ret = message.GetBody<string>();
//}
//return ret;
if (message.Properties.Keys.Contains("message-source") && (string)message.Properties["message-source"] == "evh")
{
var o = message.GetBody<System.IO.Stream>();
using (var r = new StreamReader(o))
{
ret = r.ReadToEnd();
}
}
else
{
ret = message.GetBody<string>();
}
return ret;
}
示例2: HandleRequest
private void HandleRequest(BrokeredMessage requestMessage)
{
var replyQueueName = requestMessage.ReplyTo;
var replyQueueClient = _messagingFactory.CreateQueueClient(replyQueueName);
var request = requestMessage.GetBody(_messageType);
BrokeredMessage responseMessage;
try
{
var response = InvokeGenericHandleMethod(_requestBroker, request);
responseMessage = new BrokeredMessage(response);
responseMessage.Properties.Add(MessagePropertyKeys.RequestSuccessfulKey, true);
responseMessage.Properties.Add(MessagePropertyKeys.MessageType, _messageType.FullName);
}
catch (Exception exc)
{
responseMessage = new BrokeredMessage();
responseMessage.Properties.Add(MessagePropertyKeys.RequestSuccessfulKey, false);
foreach (var prop in ExceptionDetailsAsProperties(exc)) responseMessage.Properties.Add(prop.Key, prop.Value);
}
responseMessage.CorrelationId = requestMessage.CorrelationId;
replyQueueClient.Send(responseMessage);
}
示例3: FromBrokeredMessage
public static SBMessage FromBrokeredMessage(BrokeredMessage message)
{
SBMessage ret = new SBMessage(message.GetBody());
foreach (var key in message.Properties.Keys)
ret.Headers.Add(key, message.Properties[key]);
return ret;
}
示例4: PumpMessage
protected override void PumpMessage(BrokeredMessage message)
{
var correlationId = Guid.Parse(message.CorrelationId);
var responseCorrelationWrapper = _requestResponseCorrelator.TryGetWrapper(correlationId);
if (responseCorrelationWrapper == null)
{
Logger.Debug("Could not find correlation wrapper for reply {0} ({1}", correlationId, message.Properties[MessagePropertyKeys.MessageType]);
return;
}
var success = (bool) message.Properties[MessagePropertyKeys.RequestSuccessfulKey];
if (success)
{
Logger.Debug("Request {0} was successful. Dispatching reply to correlation wrapper.", correlationId);
var responseType = responseCorrelationWrapper.ResponseType;
var response = message.GetBody(responseType);
responseCorrelationWrapper.Reply(response);
Logger.Debug("Response {0} dispatched.", correlationId);
}
else
{
var exceptionMessage = (string) message.Properties[MessagePropertyKeys.ExceptionMessageKey];
var exceptionStackTrace = (string) message.Properties[MessagePropertyKeys.ExceptionStackTraceKey];
Logger.Debug("Request {0} failed. Dispatching exception to correlation wrapper: {1} {2}", correlationId, exceptionMessage, exceptionStackTrace);
responseCorrelationWrapper.Throw(exceptionMessage, exceptionStackTrace);
}
}
示例5: ToTransportMessage
public TransportMessage ToTransportMessage(BrokeredMessage message)
{
TransportMessage t;
var rawMessage = message.GetBody<byte[]>();
if (message.Properties.Count == 0)
{
t = DeserializeMessage(rawMessage);
}
else
{
t = new TransportMessage(message.MessageId, message.Properties.ToDictionary(kvp=>kvp.Key,kvp=>kvp.Value.ToString()))
{
CorrelationId = message.CorrelationId,
TimeToBeReceived = message.TimeToLive
};
t.MessageIntent =
(MessageIntentEnum)
Enum.Parse(typeof(MessageIntentEnum), message.Properties[Headers.MessageIntent].ToString());
if ( !String.IsNullOrWhiteSpace( message.ReplyTo ) )
{
t.ReplyToAddress = Address.Parse( message.ReplyTo ); // Will this work?
}
t.Body = rawMessage;
}
return t;
}
示例6: BuildMessage
/// <summary>
/// Convert the brokered message to an envelope.
/// </summary>
/// <param name="brokeredMessage"></param>
/// <returns></returns>
public async Task<IEnvelope<IMessage>> BuildMessage(BrokeredMessage brokeredMessage)
{
using (var stream = brokeredMessage.GetBody<Stream>())
using (var ms = new MemoryStream())
{
var messageType = brokeredMessage.ContentType;
// Log.
MessagingEventSource.Log.DeserializingMessage(messageType, brokeredMessage.MessageId, brokeredMessage.CorrelationId, brokeredMessage.SessionId);
// Helps us get access to the byte array.
await stream.CopyToAsync(ms);
// Build the envelope.
var envelope = Envelope.Create<IMessage>(null)
.CorrelationId(brokeredMessage.CorrelationId)
.SessionId(brokeredMessage.SessionId)
.TimeToLive(brokeredMessage.TimeToLive)
.Properties(brokeredMessage.Properties);
// Handle interceptors, then deserialize.
var serializedMessage = await Configuration.MessageFilterInvoker.BeforeDeserialization(envelope, ms.ToArray());
var message = await Configuration.Serializer.Deserialize<IMessage>(serializedMessage);
// Log.
MessagingEventSource.Log.DeserializationComplete(messageType, brokeredMessage.MessageId, brokeredMessage.CorrelationId, brokeredMessage.SessionId);
// Done.
return envelope.Body(message);
}
}
示例7: Consume
/// <summary>
/// Consumes the specified message.
/// </summary>
/// <param name="message">The message.</param>
public void Consume(BrokeredMessage message)
{
try
{
var msg = message.GetBody<QueueLogMessage>();
//Get message from storage account.
var rawBytes = _storage.GetFile(QueueConstants.LoggingQueue, msg.Id.ToString());
var text = Encoding.Default.GetString(rawBytes);
//make a post to loggly with content.
var client = new RestClient();
var request = new RestRequest(msg.Endpoint);
request.AddParameter("application/json", text, ParameterType.RequestBody);
request.Method = Method.POST;
client.Execute(request);
//remove message from storage account.
_storage.DeleteFile(QueueConstants.LoggingQueue, msg.Id.ToString());
}
catch (Exception ex)
{
var logToFileSystem = new LogToFile(_settings.LoggingFilePath);
logToFileSystem.Exception(ex);
}
}
示例8: 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();
}
}
示例9: OnMessageReceived
private void OnMessageReceived(BrokeredMessage brokeredMsg)
{
var msg = JsonConvert.DeserializeObject<Message>(brokeredMsg.GetBody<string>());
if (_messageCallback(msg))
{
brokeredMsg.Complete();
}
}
示例10: ServiceBusQueueFetchedJob
public ServiceBusQueueFetchedJob(BrokeredMessage message)
{
if (message == null) throw new ArgumentNullException("message");
_message = message;
JobId = _message.GetBody<string>();
}
示例11: AzureBrokeredMessageEnvelopInbound
/// <summary>
/// Constructor - AzureBrokeredMessage
/// </summary>
public AzureBrokeredMessageEnvelopInbound(BrokeredMessage azureMsg)
{
_message = azureMsg;
Message = _message.GetBody();
ReplyTo = string.IsNullOrEmpty(_message.ReplyTo) ? string.Empty : _message.ReplyTo;
ContentType = string.IsNullOrEmpty(_message.ContentType) ? string.Empty : _message.ContentType;
azureMsg.Properties.ForEach(x => PinkoProperties[x.Key] = x.Value.ToString());
}
示例12: test
public void test()
{
var body = "{\"ChunkUid\":{\"JobId\":\"job1\",\"SplitId\":\"d54f9e43-a754-496f-b57f-20cbb6ced358\"},\"Data\":\"hello from mapper\",\"ProcessorNodeId\":\"node1\"}";
using (var ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(body)))
{
var msg = new BrokeredMessage(body);
var s = msg.GetBody<string>();
s = null;
}
}
示例13: ServiceBusBasicMessage
public ServiceBusBasicMessage(BrokeredMessage message)
{
ContentType = message.ContentType;
CorrelationId = message.CorrelationId;
Label = message.Label;
MessageId = message.MessageId;
Properties = message.Properties;
SessionId = message.SessionId;
Content = message.GetBody<string>();
}
示例14: AzureBrokeredMessageEnvelopInbound
/// <summary>
/// Constructor - AzureBrokeredMessage
/// </summary>
public AzureBrokeredMessageEnvelopInbound(IPinkoApplication pinkoApplication, BrokeredMessage azureMsg)
: base(pinkoApplication)
{
_message = azureMsg;
Message = _message.GetBody();
ReplyTo = string.IsNullOrEmpty(_message.ReplyTo) ? string.Empty : _message.ReplyTo;
azureMsg.Properties.ForEach(x => PinkoProperties[x.Key] = x.Value.ToString());
}
示例15: GetCommandBody
public ICommand GetCommandBody(BrokeredMessage brokeredMessage)
{
var contentType = brokeredMessage.ContentType;
var bodyType = Type.GetType(contentType, true);
var stream = brokeredMessage.GetBody<Stream>();
var serializer = new DataContractSerializer(bodyType);
var reader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max);
var deserializedBody = serializer.ReadObject(reader);
return (ICommand)deserializedBody;
}