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


C# IBasicProperties.SetPersistent方法代码示例

本文整理汇总了C#中IBasicProperties.SetPersistent方法的典型用法代码示例。如果您正苦于以下问题:C# IBasicProperties.SetPersistent方法的具体用法?C# IBasicProperties.SetPersistent怎么用?C# IBasicProperties.SetPersistent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IBasicProperties的用法示例。


在下文中一共展示了IBasicProperties.SetPersistent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

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

示例2: Enqueue

 /// <summary>
 /// 入队操作
 /// </summary>
 /// <param name="bytes"></param>
 /// <param name="property"></param>
 /// <param name="persistent"></param>
 public static void Enqueue(byte[] bytes, IBasicProperties property, bool persistent = false)
 {
     IModel channel = channels[new Random().Next(0, channels_num)];  //随机选取channel发送数据
     if (property == null) property = channel.CreateBasicProperties();  //额外的属性,添加消息头的
     property.SetPersistent(persistent);  //消息持久化
     channel.BasicPublish(exchange_name, route_key, property, bytes);
 }
开发者ID:wangyang602117818,项目名称:EasyOa.Common,代码行数:13,代码来源:LogEnqueue.cs

示例3: RabbitMq

        public RabbitMq(bool durable)
        {
            _connection = _factory.CreateConnection();
            _session = durable ? _connection.CreateDurableSession() : _connection.CreateNonDurableSession();
            _props = _session.Model.CreateBasicProperties();
            _props.SetPersistent(true);

            _consumeThread = new Thread(ReadMessages);
        }
开发者ID:bling,项目名称:MessageQueuePerfTest,代码行数:9,代码来源:RabbitMq.cs

示例4: FillRabbitMqProperties

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

            if (!String.IsNullOrEmpty(message.CorrelationId))
            {
                properties.CorrelationId = message.CorrelationId;
            }

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

            properties.SetPersistent(message.Recoverable);

            properties.Headers = message.Headers.ToDictionary(p => p.Key, p => (object)p.Value);

            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";
            }

            var replyToAddress = options.ReplyToAddress ?? message.ReplyToAddress;
            if (replyToAddress != null)
            {
                properties.ReplyTo = replyToAddress.Queue;
            }
        }
开发者ID:MyDealerLot,项目名称:NServiceBus.RabbitMQ,代码行数:41,代码来源:RabbitMqTransportMessageExtensions.cs

示例5: Translate

		protected virtual BasicDeliverEventArgs Translate(ChannelMessage message, IBasicProperties properties)
		{
			var serializer = this.configuration.Serializer;

			properties.MessageId = message.MessageId.ToNull() ?? string.Empty;
			properties.CorrelationId = message.CorrelationId.ToNull() ?? string.Empty;
			properties.AppId = this.configuration.ApplicationId;
			properties.ContentEncoding = serializer.ContentEncoding ?? string.Empty;

			properties.ContentType = string.IsNullOrEmpty(serializer.ContentFormat)
				? ContentType : ContentType + "+" + serializer.ContentFormat;

			properties.SetPersistent(message.Persistent);

			var expiration = message.Expiration;
			properties.Expiration = (expiration == DateTime.MinValue || expiration == DateTime.MaxValue)
				? string.Empty : expiration.ToEpochTime().ToString(CultureInfo.InvariantCulture);

			if (message.ReturnAddress != null)
				properties.ReplyTo = message.ReturnAddress.ToString();

			var messages = (message.Messages ?? new object[0]).ToArray();
			var payload = serializer.Serialize(messages);

			properties.Headers = new Hashtable((IDictionary)message.Headers);
			properties.Type = messages[0].GetType().FullName;
			properties.Timestamp = new AmqpTimestamp(SystemTime.UtcNow.ToEpochTime());

			return new BasicDeliverEventArgs
			{
				Body = payload,
				RoutingKey = this.configuration.LookupRoutingKey(message),
				BasicProperties = properties
			};
		}
开发者ID:akurtov,项目名称:NanoMessageBus,代码行数:35,代码来源:RabbitMessageAdapter.cs

示例6: Translate

		protected virtual BasicDeliverEventArgs Translate(ChannelMessage message, IBasicProperties properties)
		{
			var serializer = this.configuration.Serializer;

			properties.MessageId = message.MessageId.ToNull() ?? string.Empty;
			properties.CorrelationId = message.CorrelationId.ToNull() ?? string.Empty;
			properties.AppId = this.configuration.ApplicationId;
			properties.ContentEncoding = serializer.ContentEncoding ?? string.Empty;

			properties.ContentType = string.IsNullOrEmpty(serializer.ContentFormat)
				? ContentType : ContentType + "+" + serializer.ContentFormat;

			properties.SetPersistent(message.Persistent);
			SetExpiration(properties, message);

			if (message.ReturnAddress != null)
				properties.ReplyTo = message.ReturnAddress.ToString();

			var messages = (message.Messages ?? new object[0]).ToArray();
			var payload = messages.Length > 1 ? serializer.Serialize(messages) : serializer.Serialize(messages[0]);
			properties.Headers = new Dictionary<string, object>(message.Headers.Count);
			foreach (var item in message.Headers)
				properties.Headers[item.Key] = item.Value;

			var type = messages[0].GetType();
			properties.Type = MessageTypeFormat.FormatWith(type.FullName, type.Assembly.GetName().Name);
			properties.Timestamp = new AmqpTimestamp(SystemTime.UtcNow.ToEpochTime());

			return new BasicDeliverEventArgs
			{
				Body = payload,
				RoutingKey = this.configuration.LookupRoutingKey(message),
				BasicProperties = properties
			};
		}
开发者ID:yonglehou,项目名称:NanoMessageBus,代码行数:35,代码来源:RabbitMessageAdapter.cs


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