本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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;
}
}
示例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
};
}
示例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
};
}