• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TransportMessage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中TransportMessage的典型用法代码示例。如果您正苦于以下问题:C# TransportMessage类的具体用法?C# TransportMessage怎么用?C# TransportMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TransportMessage类属于命名空间,在下文中一共展示了TransportMessage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: MapToTransportMessage

        TransportMessage MapToTransportMessage(TimeoutData timeoutData)
        {
            var transportMessage = new TransportMessage
                                       {
                                           ReplyToAddress = Address.Local,
                                           Headers = new Dictionary<string, string>(),
                                           Recoverable = true,
                                           MessageIntent = MessageIntentEnum.Send,
                                           CorrelationId = timeoutData.CorrelationId,
                                           Body = timeoutData.State
                                       };

            if (timeoutData.Headers != null)
            {
                transportMessage.Headers = timeoutData.Headers;
            }
            else
            {
                //we do this to be backwards compatible, this can be removed when going to 3.1.X
                transportMessage.Headers[Headers.Expire] = timeoutData.Time.ToWireFormattedString();

                if (timeoutData.SagaId != Guid.Empty)
                    transportMessage.Headers[Headers.SagaId] = timeoutData.SagaId.ToString();

            }

            return transportMessage;
        }
开发者ID:dwarry,项目名称:NServiceBus,代码行数:28,代码来源:TimeoutRunner.cs


示例2: GetRemoteAddress

        string GetRemoteAddress(TransportMessage msg)
        {
            if (msg.Headers.ContainsKey(Headers.HttpTo))
                return msg.Headers[Headers.HttpTo];

            return remoteUrl;
        }
开发者ID:Jpattom,项目名称:NServiceBus,代码行数:7,代码来源:LegacySiteRouter.cs


示例3: foreach

 void IMutateOutgoingTransportMessages.MutateOutgoing(IMessage[] messages, TransportMessage transportMessage)
 {
     if (messageHeaders != null)
         if (messageHeaders.ContainsKey(messages[0]))
             foreach (var key in messageHeaders[messages[0]].Keys)
                 transportMessage.Headers.Add(key, messageHeaders[messages[0]][key]);
 }
开发者ID:rsummer,项目名称:NServiceBus,代码行数:7,代码来源:When_sending_messages_to_sites.cs


示例4: Convert

        /// <summary>
        ///     Converts a TransportMessage to an Msmq message.
        ///     Doesn't set the ResponseQueue of the result.
        /// </summary>
        public static Message Convert(TransportMessage message)
        {
            var result = new Message();

            if (message.Body != null)
            {
                result.BodyStream = new MemoryStream(message.Body);
            }

            AssignMsmqNativeCorrelationId(message, result);

            result.Recoverable = message.Recoverable;

            if (message.TimeToBeReceived < MessageQueue.InfiniteTimeout)
            {
                result.TimeToBeReceived = message.TimeToBeReceived;
            }

            using (var stream = new MemoryStream())
            {
                headerSerializer.Serialize(stream, message.Headers.Select(pair => new HeaderInfo
                {
                    Key = pair.Key,
                    Value = pair.Value
                }).ToList());
                result.Extension = stream.ToArray();
            }

            result.AppSpecific = (int) message.MessageIntent;

            return result;
        }
开发者ID:89sos98,项目名称:NServiceBus,代码行数:36,代码来源:MsmqUtilities.cs


示例5: Map

        public static TransportMessage Map(IDictionary<string, string> from)
        {
            if (!from.ContainsKey(GatewayHeaders.IsGatewayMessage))
            {
                return new TransportMessage();
            }

            var headers = ExtractHeaders(from);
            var to = new TransportMessage(from[NServiceBus + Id], headers);

            to.CorrelationId = StripSlashZeroFromCorrelationId(from[NServiceBus + CorrelationId]) ?? to.Id;

            bool recoverable;
            if (bool.TryParse(from[NServiceBus + Recoverable], out recoverable))
            {
                to.Recoverable = recoverable;
            }

            TimeSpan timeToBeReceived;
            TimeSpan.TryParse(from[NServiceBus + TimeToBeReceived], out timeToBeReceived);
            to.TimeToBeReceived = timeToBeReceived;

            if (to.TimeToBeReceived < MinimumTimeToBeReceived)
            {
                to.TimeToBeReceived = MinimumTimeToBeReceived;
            }

            return to;
        }
开发者ID:afyles,项目名称:NServiceBus,代码行数:29,代码来源:HeaderMapper.cs


示例6: When_a_message_is_received_the_Handle_method_should_called_on_the_satellite

        public void When_a_message_is_received_the_Handle_method_should_called_on_the_satellite()
        {
            var tm = new TransportMessage();
            FakeReceiver.FakeMessageReceived(tm);

            Assert.That(_sat.IsMessageHandled, Is.True);
        }
开发者ID:kashyapus,项目名称:NServiceBus,代码行数:7,代码来源:SatelliteLauncherTests.cs


示例7: FillRabbitMqProperties

        public static IBasicProperties FillRabbitMqProperties(TransportMessage message, IBasicProperties properties)
        {
            properties.MessageId = message.Id;

            properties.CorrelationId = message.CorrelationId;

            if (message.TimeToBeReceived < TimeSpan.MaxValue)
                properties.Expiration = message.TimeToBeReceived.TotalMilliseconds.ToString();

            properties.SetPersistent(message.Recoverable);

            properties.Headers = message.Headers;

            if (message.Headers.ContainsKey(Headers.EnclosedMessageTypes))
            {
                properties.Type = message.Headers[Headers.EnclosedMessageTypes].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
            }

            if (message.Headers.ContainsKey(Headers.ContentType))
                properties.ContentType = message.Headers[Headers.ContentType];
            else
            {
                properties.ContentType = "application/octet-stream";
            }

            if (message.ReplyToAddress != null && message.ReplyToAddress != Address.Undefined)
                properties.ReplyTo = message.ReplyToAddress.Queue;

            return properties;
        }
开发者ID:afyles,项目名称:NServiceBus,代码行数:30,代码来源:RabbitMqTransportMessageExtensions.cs


示例8: Defer

        void Defer(TimeSpan defer, TransportMessage message)
        {
            var retryMessageAt = DateTime.UtcNow + defer;

            TransportMessageHeaderHelper.SetHeader(message, Headers.Retries,
                (TransportMessageHeaderHelper.GetNumberOfRetries(message) + 1).ToString(CultureInfo.InvariantCulture));

            var addressOfFaultingEndpoint = TransportMessageHeaderHelper.GetAddressOfFaultingEndpoint(message);

            if (!TransportMessageHeaderHelper.HeaderExists(message, SecondLevelRetriesHeaders.RetriesTimestamp))
            {
                TransportMessageHeaderHelper.SetHeader(message, SecondLevelRetriesHeaders.RetriesTimestamp,
                    DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow));
            }

            logger.DebugFormat("Defer message and send it to {0}", addressOfFaultingEndpoint);

            var sendOptions = new SendOptions(addressOfFaultingEndpoint)
            {
                DeliverAt = retryMessageAt
            };


            MessageDeferrer.Defer(message, sendOptions);
        }
开发者ID:ogdenmd,项目名称:NServiceBus,代码行数:25,代码来源:SecondLevelRetriesProcessor.cs


示例9: HasReachedMaxTime

        static bool HasReachedMaxTime(TransportMessage message)
        {
            var timestampHeader = TransportMessageHeaderHelper.GetHeader(message, SecondLevelRetriesHeaders.RetriesTimestamp);

            if (String.IsNullOrEmpty(timestampHeader))
            {
                return false;
            }

            try
            {
                var handledAt = DateTimeExtensions.ToUtcDateTime(timestampHeader);

                if (DateTime.UtcNow > handledAt.AddDays(1))
                {
                    return true;
                }
            }
                // ReSharper disable once EmptyGeneralCatchClause
                // this code won't usually throw but in case a user has decided to hack a message/headers and for some bizarre reason 
                // they changed the date and that parse fails, we want to make sure that doesn't prevent the message from being 
                // forwarded to the error queue.
            catch (Exception)
            {
            }

            return false;
        }
开发者ID:xqfgbc,项目名称:NServiceBus,代码行数:28,代码来源:SecondLevelRetriesConfiguration.cs


示例10: Defer

        public void Defer(TransportMessage message, SendOptions sendOptions)
        {
            message.Headers[TimeoutManagerHeaders.RouteExpiredTimeoutTo] = sendOptions.Destination.ToString();

            DateTime deliverAt;

            if (sendOptions.DelayDeliveryWith.HasValue)
            {
                deliverAt = DateTime.UtcNow + sendOptions.DelayDeliveryWith.Value;
            }
            else
            {
                if (sendOptions.DeliverAt.HasValue)
                {
                    deliverAt = sendOptions.DeliverAt.Value;    
                }
                else
                {
                    throw new ArgumentException("A delivery time needs to be specified for Deferred messages");
                }
                
            }

            message.Headers[TimeoutManagerHeaders.Expire] = DateTimeExtensions.ToWireFormattedString(deliverAt);
            
            try
            {
                MessageSender.Send(message, new SendOptions(TimeoutManagerAddress));
            }
            catch (Exception ex)
            {
                Log.Error("There was a problem deferring the message. Make sure that DisableTimeoutManager was not called for your endpoint.", ex);
                throw;
            }
        }
开发者ID:xqfgbc,项目名称:NServiceBus,代码行数:35,代码来源:TimeoutManagerDeferrer.cs


示例11: BuildSendCommand

        private SqlCommand BuildSendCommand(SqlConnection connection, TransportMessage transportMessage, Address address)
        {
            var command = connection.CreateCommand();

            command.CommandText = String.Format(SqlCommands.Send, address);
            command.CommandType = CommandType.Text;

            command.Parameters.AddWithValue("@Id", transportMessage.MessageId);
            command.Parameters.AddWithValue("@ReplyTo", transportMessage.ReplyToAddress.ToString());
            command.Parameters.AddWithValue("@Headers", objectSerializer.SerializeObject(transportMessage.Headers));
            command.Parameters.AddWithValue("@Body", transportMessage.Body);

            if (transportMessage.CorrelationId != Guid.Empty)
            {
                command.Parameters.AddWithValue("@CorrelationId", transportMessage.CorrelationId);
            }
            else
            {
                command.Parameters.AddWithValue("@CorrelationId", DBNull.Value);
            }

            if (transportMessage.HasExpiryTime)
            {
                command.Parameters.AddWithValue("@Expires", transportMessage.ExpiryTime);
            }
            else
            {
                command.Parameters.AddWithValue("@Expires", DBNull.Value);
            }

            return command;
        }
开发者ID:kehinze,项目名称:Hermes,代码行数:32,代码来源:SqlMessageSender.cs


示例12: Send

        public void Send(object messageToSend, TimeSpan timeToBeReceived)
        {
            var message = new TransportMessage
            {
                TimeToBeReceived = timeToBeReceived
            };

            using (var stream = new MemoryStream())
            {
                serializer.Serialize(new[] { messageToSend }, stream);
                message.Body = stream.ToArray();
            }

            //hack to remove the type info from the json
            var bodyString = Encoding.UTF8.GetString(message.Body);

            var toReplace = ", " + messageToSend.GetType().Assembly.GetName().Name;

            bodyString = bodyString.Replace(toReplace, ", ServiceControl");

            message.Body = Encoding.UTF8.GetBytes(bodyString);
            // end hack
            message.Headers[Headers.EnclosedMessageTypes] = messageToSend.GetType().FullName;
            message.Headers[Headers.ContentType] = ContentTypes.Json; //Needed for ActiveMQ transport

            try
            {
                messageSender.Send(message, new SendOptions(serviceControlBackendAddress) { ReplyToAddress = configure.LocalAddress });
                circuitBreaker.Success();
            }
            catch (Exception ex)
            {
                circuitBreaker.Failure(ex);
            }            
        }
开发者ID:Particular,项目名称:ServiceControl.Plugin.Nsb5.CustomChecks,代码行数:35,代码来源:ServiceControlBackend.cs


示例13: MutateIncoming

        /// <summary>
        /// Stores the original saga id and type of the incoming message
        /// </summary>
        /// <param name="transportMessage"></param>
        public void MutateIncoming(TransportMessage transportMessage)
        {
            originatingSagaId = null;
            originatingSagaType = null;

            // We need this for backwards compatibility because in v4.0.0 we still have this headers being sent as part of the message even if MessageIntent == MessageIntentEnum.Publish
            if (transportMessage.MessageIntent == MessageIntentEnum.Publish)
            {
                if (transportMessage.Headers.ContainsKey(Headers.SagaId))
                {
                    transportMessage.Headers.Remove(Headers.SagaId);
                }

                if (transportMessage.Headers.ContainsKey(Headers.SagaType))
                {
                    transportMessage.Headers.Remove(Headers.SagaType);
                }
            }

            if (transportMessage.Headers.ContainsKey(Headers.OriginatingSagaId))
            {
                originatingSagaId = transportMessage.Headers[Headers.OriginatingSagaId];
            }

            if (transportMessage.Headers.ContainsKey(Headers.OriginatingSagaType))
            {
                originatingSagaType = transportMessage.Headers[Headers.OriginatingSagaType];
            }
        }
开发者ID:petarvucetin,项目名称:NServiceBus,代码行数:33,代码来源:AutoCorrelateSagaOnReplyMutator.cs


示例14: 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


示例15: HandleProcessingAlwaysFailsForMessage

        void HandleProcessingAlwaysFailsForMessage(TransportMessage message, Exception e, int numberOfRetries)
        {
            message.SetExceptionHeaders(e, localAddress ?? config.LocalAddress);

            if (MessageWasSentFromSLR(message))
            {
                SendToErrorQueue(message, e);
                return;
            }

            var flrPart = numberOfRetries > 0
                ? $"Message with '{message.Id}' id has failed FLR and"
                : $"FLR is disabled and the message '{message.Id}'";

            //HACK: We need this hack here till we refactor the SLR to be a first class concept in the TransportReceiver
            if (RetriesQueue == null)
            {
                Logger.ErrorFormat("{0} will be moved to the configured error queue.", flrPart);
                SendToErrorQueue(message, e);
                return;
            }

            var defer = SecondLevelRetriesConfiguration.RetryPolicy.Invoke(message);

            if (defer < TimeSpan.Zero)
            {
                Logger.ErrorFormat(
                    "SLR has failed to resolve the issue with message {0} and will be forwarded to the error queue at {1}",
                    message.Id, ErrorQueue);
                SendToErrorQueue(message, e);
                return;
            }

            SendToRetriesQueue(message, e, flrPart);
        }
开发者ID:hyldrim,项目名称:NServiceBus,代码行数:35,代码来源:FaultManager.cs


示例16: MapToHeaders

        Dictionary<string,string> MapToHeaders(TransportMessage from)
        {
            var to = new Dictionary<string, string>(StringComparer.CurrentCultureIgnoreCase);

            to[NServiceBus + Id] = from.Id;
            to[NServiceBus + CorrelationId] = GetCorrelationForBackwardsCompatibility(from);
            to[NServiceBus + Recoverable] = from.Recoverable.ToString();
            to[NServiceBus + TimeToBeReceived] = from.TimeToBeReceived.ToString();

            if (from.ReplyToAddress != null) //Handles SendOnly endpoints, where ReplyToAddress is not set
            {
                to[NServiceBus + ReplyToAddress] = from.ReplyToAddress.ToString();
            }

            SetBackwardsCompatibilityHeaders(to);

            string replyToAddress;
            if (from.Headers.TryGetValue(ReplyToAddress, out replyToAddress))
            {
                to[Headers.RouteTo] = replyToAddress;
            }

            from.Headers.ToList()
                .ForEach(header => to[NServiceBus + Headers.HeaderName + "." + header.Key] = header.Value);

            return to;
        }
开发者ID:ramonsmits,项目名称:NServiceBus.Gateway,代码行数:27,代码来源:SingleCallChannelForwarder.cs


示例17: ToTransportMessage

        public static TransportMessage ToTransportMessage(this BrokeredMessage message)
        {
            TransportMessage t;
            var rawMessage = BrokeredMessageBodyConversion.ExtractBody(message);

            if (message.Properties.Count > 0)
            {
                var headers = message.Properties.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as string);
                if (!String.IsNullOrWhiteSpace(message.ReplyTo))
                {
                    headers[Headers.ReplyToAddress] = message.ReplyTo;
                }

                t = new TransportMessage(message.MessageId, headers)
                {
                    CorrelationId = message.CorrelationId,
                    TimeToBeReceived = message.TimeToLive,
                    MessageIntent = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), message.Properties[Headers.MessageIntent].ToString()),
                    Body = rawMessage
                };
            }
            else
            {
                t = new TransportMessage
                {
                    Body = rawMessage
                };
            }

            return t;
        }
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:31,代码来源:BrokeredMessageConverter.cs


示例18: Handle

 public bool Handle(TransportMessage errorMessage)
 {
     transport.PipelineFactory
           .GetPipeline(errorPipelineName)
           .Push(errorMessage.AsEndpointMessage(serializer, endpointWhereErrorOccured));
     return true;
 }
开发者ID:fetishism,项目名称:Cronus,代码行数:7,代码来源:EndpointPostConsumeStrategy.cs


示例19: Send

 public void Send(TransportMessage message, Address address)
 {
    using(var redisClient = new RedisClient())
    {
        redisClient.Add(string.Format("{0}:{1}", address.Machine, address.Queue), message);
    }
 }
开发者ID:kstenson,项目名称:NServicebus.Redis,代码行数:7,代码来源:RedisQueue.cs


示例20: Handle

        public bool Handle(TransportMessage message)
        {
            var destinationSites = GetDestinationSitesFor(message);

            //if there is more than 1 destination we break it up into multiple messages
            if (destinationSites.Count() > 1)
            {
                foreach (var destinationSite in destinationSites)
                {
                    CloneAndSendLocal(message, destinationSite);
                }

                return true;
            }

            var destination = destinationSites.FirstOrDefault();

            if (destination == null)
            {
                throw new InvalidOperationException("No destination found for message");
            }

            SendToSite(message, destination);

            return true;
        }
开发者ID:petarvucetin,项目名称:NServiceBus,代码行数:26,代码来源:GatewaySender.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TransportMessageToSend类代码示例发布时间:2022-05-24
下一篇:
C# TransportContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap