当前位置: 首页>>代码示例>>C#>>正文


C# BrokeredMessage.GetBody方法代码示例

本文整理汇总了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;
        }
开发者ID:michael-chi,项目名称:Azure-IOTHub,代码行数:32,代码来源:Functions.cs

示例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);
        }
开发者ID:nhuhuynh,项目名称:Nimbus,代码行数:25,代码来源:RequestMessagePump.cs

示例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;
 }
开发者ID:HaishiBai,项目名称:EnterpriseIntegrationPatterns,代码行数:7,代码来源:SBMessage.cs

示例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);
            }
        }
开发者ID:Joshscorp,项目名称:Nimbus,代码行数:31,代码来源:ResponseMessagePump.cs

示例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;
        }
开发者ID:afyles,项目名称:NServiceBus,代码行数:31,代码来源:BrokeredMessageConverter.cs

示例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);
            }
        }
开发者ID:RobinSoenen,项目名称:RedDog,代码行数:36,代码来源:MessageProcessor.cs

示例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);
            }
        }
开发者ID:chuckconway,项目名称:momntz-worker-legacy,代码行数:30,代码来源:LoggerSaga.cs

示例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();
            }
        }
开发者ID:RichardW1001,项目名称:MessagingStuff,代码行数:25,代码来源:MessageBus.cs

示例9: OnMessageReceived

 private void OnMessageReceived(BrokeredMessage brokeredMsg)
 {
     var msg = JsonConvert.DeserializeObject<Message>(brokeredMsg.GetBody<string>());
     if (_messageCallback(msg))
     {
         brokeredMsg.Complete();
     }
 }
开发者ID:tamifist,项目名称:KinderChat,代码行数:8,代码来源:ProcessedMessagesQueue.cs

示例10: ServiceBusQueueFetchedJob

        public ServiceBusQueueFetchedJob(BrokeredMessage message)
        {
            if (message == null) throw new ArgumentNullException("message");

            _message = message;

            JobId = _message.GetBody<string>();
        }
开发者ID:wimagee,项目名称:Hangfire.Azure.ServiceBusQueue,代码行数:8,代码来源:ServiceBusQueueFetchedJob.cs

示例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());
        }
开发者ID:cotmechy,项目名称:PinkoAzure,代码行数:13,代码来源:AzureBrokeredMessageEnvelopInbound.cs

示例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;
     }
 }
开发者ID:hugebdu,项目名称:MapReduce.JS,代码行数:10,代码来源:MapResultGenerator.cs

示例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>();
 }
开发者ID:jeffhollan,项目名称:ServiceBusSessionID,代码行数:10,代码来源:ServiceBusBasicMessage.cs

示例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());
        }
开发者ID:cotmechy,项目名称:PinkoAzure,代码行数:13,代码来源:AzureBrokeredMessageEnvelopInbound.cs

示例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;
        }
开发者ID:johnm25,项目名称:SeekU,代码行数:11,代码来源:WorkerRole.cs


注:本文中的BrokeredMessage.GetBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。