本文整理汇总了C#中IModel.CreateBasicProperties方法的典型用法代码示例。如果您正苦于以下问题:C# IModel.CreateBasicProperties方法的具体用法?C# IModel.CreateBasicProperties怎么用?C# IModel.CreateBasicProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IModel
的用法示例。
在下文中一共展示了IModel.CreateBasicProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public virtual IBasicProperties Create(IModel channel, MessageProperties properties)
{
var basicProperties = channel.CreateBasicProperties();
if(!string.IsNullOrWhiteSpace(properties.MessageId))
{
basicProperties.MessageId = properties.MessageId;
}
if(!string.IsNullOrWhiteSpace(properties.CorrelationId))
{
basicProperties.CorrelationId = properties.CorrelationId;
}
if(!string.IsNullOrWhiteSpace(properties.ContentType))
{
basicProperties.ContentType = properties.ContentType;
}
if(!string.IsNullOrWhiteSpace(properties.ContentEncoding))
{
basicProperties.ContentEncoding = properties.ContentEncoding;
}
basicProperties.DeliveryMode = (byte) properties.DeliveryMode;
if(properties.Headers.Keys.Any())
{
basicProperties.Headers = new Dictionary<object, object>();
foreach(var key in properties.Headers.Keys)
{
basicProperties.Headers.Add(key, properties.Headers[key]);
}
}
return basicProperties;
}
示例2: CallService
private void CallService(IModel channel, string queueName)
{
var properties = channel.CreateBasicProperties();
properties.ReplyTo = queueName;
properties.CorrelationId = (++correlationId).ToString();
channel.BasicPublish("", Constants.RpcQueueName, properties, Encoding.UTF8.GetBytes(n.ToString()));
}
示例3: SendMessage
void SendMessage(TransportMessage message, SendOptions sendOptions, IModel channel)
{
var destination = sendOptions.Destination;
string callbackAddress;
if (sendOptions.GetType().FullName.EndsWith("ReplyOptions") &&
message.Headers.TryGetValue(CallbackHeaderKey, out callbackAddress))
{
destination = Address.Parse(callbackAddress);
}
//set our callback address
if (!string.IsNullOrEmpty(CallbackQueue))
{
message.Headers[CallbackHeaderKey] = CallbackQueue;
}
var properties = channel.CreateBasicProperties();
RabbitMqTransportMessageExtensions.FillRabbitMqProperties(message, sendOptions, properties);
RoutingTopology.Send(channel, destination, message, properties);
}
示例4: CreatePropertiesFactory
private Func<RogerEndpoint, IBasicProperties> CreatePropertiesFactory(IModel model,
IIdGenerator idGenerator,
IMessageTypeResolver messageTypeResolver,
IMessageSerializer serializer,
ISequenceGenerator sequenceGenerator)
{
var properties = model.CreateBasicProperties();
properties.MessageId = idGenerator.Next();
properties.Type = messageTypeResolver.Unresolve(messageType);
properties.ContentType = serializer.ContentType;
properties.Headers = new Hashtable
{
{Headers.Sequence, BitConverter.GetBytes(sequenceGenerator.Next(messageType))}
};
if (persistent)
properties.DeliveryMode = 2;
FillAdditionalProperties(properties, idGenerator);
return endpoint =>
{
properties.ReplyTo = endpoint;
return properties;
};
}
示例5: CreateDefaultProperties
public static IBasicProperties CreateDefaultProperties(IModel model) {
var properties = model.CreateBasicProperties();
properties.SetPersistent(true);
properties.ContentType = "application/json";
properties.ContentEncoding = "UTF-8";
return properties;
}
示例6: SendDurableMessageToDurableQueue
private static void SendDurableMessageToDurableQueue(IModel model)
{
IBasicProperties basicProperties = model.CreateBasicProperties();
basicProperties.SetPersistent(true);
byte[] payload = Encoding.UTF8.GetBytes("This is a persistent message from Visual Studio");
PublicationAddress address = new PublicationAddress(ExchangeType.Topic, "DurableExchange", "durable");
model.BasicPublish(address, basicProperties, payload);
}
示例7: BasicMessageBuilder
///<summary>Construct an instance ready for writing.</summary>
public BasicMessageBuilder(IModel model, int initialAccumulatorSize) {
m_properties = model.CreateBasicProperties();
m_accumulator = new MemoryStream(initialAccumulatorSize);
string contentType = GetDefaultContentType();
if (contentType != null) {
Properties.ContentType = contentType;
}
}
示例8: GetBasicProperties
private static IBasicProperties GetBasicProperties(string messageUri, IModel channel)
{
var bp = channel.CreateBasicProperties();
bp.ContentType = "application/skutt";
bp.SetPersistent(true);
bp.CorrelationId = Guid.NewGuid().ToString();
bp.Type = messageUri;
return bp;
}
示例9: Publish
public void Publish(IModel model, string queue, string message)
{
var properties = model.CreateBasicProperties();
properties.SetPersistent(true);
var nextPublishSeqNo = model.NextPublishSeqNo;
Console.Out.WriteLine("Published seq no = {0}", nextPublishSeqNo);
model.BasicPublish("", queue, properties, Encoding.UTF8.GetBytes(message));
}
示例10: TextParameters
public static MessageParameters TextParameters(IModel model, string type, string messageId,
DateTime timestamp)
{
IBasicProperties properties = model.CreateBasicProperties();
properties.ContentType = "text/plain";
properties.DeliveryMode = 1;
properties.MessageId = messageId;
properties.Timestamp = new AmqpTimestamp(timestamp.Ticks);
properties.Type = type;
return new MessageParameters(properties);
}
示例11: ScheduleTask
private static void ScheduleTask(string message, IModel channel)
{
message = (!String.IsNullOrEmpty(message))
? message
: "Hello World!";
byte[] body = System.Text.Encoding.UTF8.GetBytes(message);
IBasicProperties properties = channel.CreateBasicProperties();
properties.DeliveryMode = 2;
channel.BasicPublish("", "task_queue", properties, body);
Console.WriteLine(" [x] Sent {0}", message);
}
示例12: RunBadMessageDemo
private static void RunBadMessageDemo(IModel model)
{
Console.WriteLine("Enter your message. Quit with 'q'.");
while (true)
{
string message = Console.ReadLine();
if (message.ToLower() == "q") break;
IBasicProperties basicProperties = model.CreateBasicProperties();
basicProperties.SetPersistent(true);
byte[] messageBuffer = Encoding.UTF8.GetBytes(message);
model.BasicPublish("", RabbitMqService.BadMessageBufferedQueue, basicProperties, messageBuffer);
}
}
示例13: DemoQueue
// Sends a message to a queue to be handled by available worker
static void DemoQueue(IModel model)
{
model.QueueDeclare("myqueue", true, false, false, null);
var properties = model.CreateBasicProperties();
properties.SetPersistent(true);
while (true)
{
var message = Console.ReadLine();
var body = Encoding.UTF8.GetBytes(message);
model.BasicPublish("", "myqueue", properties, body);
}
}
示例14: RunChunkedMessageExample
private static void RunChunkedMessageExample(IModel model)
{
string filePath = @"c:\large_file.txt";
int chunkSize = 4096;
while (true)
{
ConsoleKeyInfo keyInfo = Console.ReadKey();
if (keyInfo.Key == ConsoleKey.Enter)
{
Console.WriteLine("Starting file read operation...");
FileStream fileStream = File.OpenRead(filePath);
StreamReader streamReader = new StreamReader(fileStream);
int remainingFileSize = Convert.ToInt32(fileStream.Length);
int totalFileSize = Convert.ToInt32(fileStream.Length);
bool finished = false;
string randomFileName = string.Concat("large_chunked_file_", Guid.NewGuid(), ".txt");
byte[] buffer;
while (true)
{
if (remainingFileSize <= 0) break;
int read = 0;
if (remainingFileSize > chunkSize)
{
buffer = new byte[chunkSize];
read = fileStream.Read(buffer, 0, chunkSize);
}
else
{
buffer = new byte[remainingFileSize];
read = fileStream.Read(buffer, 0, remainingFileSize);
finished = true;
}
IBasicProperties basicProperties = model.CreateBasicProperties();
basicProperties.SetPersistent(true);
basicProperties.Headers = new Dictionary<string, object>();
basicProperties.Headers.Add("output-file", randomFileName);
basicProperties.Headers.Add("finished", finished);
model.BasicPublish("", RabbitMqService.ChunkedMessageBufferedQueue, basicProperties, buffer);
remainingFileSize -= read;
}
Console.WriteLine("Chunks complete.");
}
}
}
示例15: RunBufferedMessageExample
private static void RunBufferedMessageExample(IModel model)
{
string filePath = @"c:\large_file.txt";
ConsoleKeyInfo keyInfo = Console.ReadKey();
while (true)
{
if (keyInfo.Key == ConsoleKey.Enter)
{
IBasicProperties basicProperties = model.CreateBasicProperties();
basicProperties.SetPersistent(true);
byte[] fileContents = File.ReadAllBytes(filePath);
model.BasicPublish("", RabbitMqService.LargeMessageBufferedQueue, basicProperties, fileContents);
}
keyInfo = Console.ReadKey();
}
}