本文整理汇总了C#中TransportMessageToSend类的典型用法代码示例。如果您正苦于以下问题:C# TransportMessageToSend类的具体用法?C# TransportMessageToSend怎么用?C# TransportMessageToSend使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransportMessageToSend类属于命名空间,在下文中一共展示了TransportMessageToSend类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Send
public void Send(string destinationQueueName, TransportMessageToSend message, ITransactionContext context)
{
var outputQueue = cloudQueueClient.GetQueueReference(destinationQueueName);
using (var memoryStream = new MemoryStream())
{
var formatter = new BinaryFormatter();
var receivedTransportMessage = new ReceivedTransportMessage
{
Id = Guid.NewGuid().ToString(),
Headers = message.Headers,
Body = message.Body,
Label = message.Label,
};
formatter.Serialize(memoryStream, receivedTransportMessage);
memoryStream.Position = 0;
var cloudQueueMessage = new CloudQueueMessage(memoryStream.ToArray());
var timeToLive = GetTimeToLive(message);
if (timeToLive.HasValue)
{
outputQueue.AddMessage(cloudQueueMessage, timeToLive.Value);
}
else
{
outputQueue.AddMessage(cloudQueueMessage);
}
}
}
开发者ID:nls75,项目名称:Rebus,代码行数:31,代码来源:AzureMessageQueue.cs
示例2: Send
/// <summary>
/// Sends a copy of the specified <see cref="TransportMessageToSend"/> using the underlying implementation of <see cref="ISendMessages"/>
/// with an encrypted message body and additional headers
/// </summary>
public void Send(string destinationQueueName, TransportMessageToSend message, ITransactionContext context)
{
var clone = new TransportMessageToSend
{
Headers = message.Headers.Clone(),
Label = message.Label,
Body = message.Body,
};
if (compressionHelper != null)
{
var compresssionResult = compressionHelper.Compress(clone.Body);
if (compresssionResult.Item1)
{
clone.Headers[Headers.Compression] = Headers.CompressionTypes.GZip;
}
clone.Body = compresssionResult.Item2;
}
if (encryptionHelper != null)
{
var iv = encryptionHelper.GenerateNewIv();
clone.Body = encryptionHelper.Encrypt(clone.Body, iv);
clone.Headers[Headers.Encrypted] = null;
clone.Headers[Headers.EncryptionSalt] = iv;
}
innerSendMessages.Send(destinationQueueName, clone, context);
}
开发者ID:JanRou,项目名称:Rebus,代码行数:33,代码来源:EncryptionAndCompressionTransportDecorator.cs
示例3: GetTimeToLive
private TimeSpan? GetTimeToLive(TransportMessageToSend message)
{
if (message.Headers != null && message.Headers.ContainsKey(Headers.TimeToBeReceived))
{
return TimeSpan.Parse((string)message.Headers[Headers.TimeToBeReceived]);
}
return null;
}
开发者ID:nls75,项目名称:Rebus,代码行数:9,代码来源:AzureMessageQueue.cs
示例4: Send
public void Send(string destinationQueueName, TransportMessageToSend message)
{
var transportMessageToSend = new TransportMessageToSend
{
Headers = message.Headers,
Label = message.Label,
Body = Encrypt(message.Body),
};
innerSendMessages.Send(destinationQueueName, transportMessageToSend);
}
开发者ID:karmerk,项目名称:Rebus,代码行数:11,代码来源:EncryptionFilter.cs
示例5: AddsHeaderToEncryptedMessage
public void AddsHeaderToEncryptedMessage()
{
// arrange
var transportMessageToSend = new TransportMessageToSend { Body = new byte[] { 123, 125 } };
// act
transport.Send("somewhere", transportMessageToSend, new NoTransaction());
// assert
sender.SentMessage.Headers.ShouldContainKey(Headers.Encrypted);
}
开发者ID:rasmuskl,项目名称:Rebus,代码行数:11,代码来源:TestRijndaelEncryptionTransportDecorator.cs
示例6: Send
public void Send(string destinationQueueName, TransportMessageToSend message, ITransactionContext context)
{
var iv = helper.GenerateNewIv();
var transportMessageToSend = new TransportMessageToSend
{
Headers = message.Headers.Clone(),
Label = message.Label,
Body = helper.Encrypt(message.Body, iv),
};
transportMessageToSend.Headers[Headers.Encrypted] = null;
transportMessageToSend.Headers[Headers.EncryptionSalt] = iv;
innerSendMessages.Send(destinationQueueName, transportMessageToSend, context);
}
开发者ID:rasmuskl,项目名称:Rebus,代码行数:16,代码来源:RijndaelEncryptionTransportDecorator.cs
示例7: CheckSendPerformance
public void CheckSendPerformance(int count)
{
var queue = new MsmqMessageQueue("test.msmq.performance", "error").PurgeInputQueue();
var transportMessageToSend = new TransportMessageToSend
{
Headers = new Dictionary<string, string>(),
Body = new byte[1024],
Label = "this is just a label"
};
var stopwatch = Stopwatch.StartNew();
count.Times(() => queue.Send("test.msmq.performance", transportMessageToSend));
var totalSeconds = stopwatch.Elapsed.TotalSeconds;
Console.WriteLine("Sending {0} messages took {1:0} s - that's {2:0} msg/s",
count, totalSeconds, count/totalSeconds);
}
开发者ID:asgerhallas,项目名称:Rebus,代码行数:17,代码来源:TestMsmqMessageQueue.cs
示例8: Send
/// <summary>
/// Sends the specified message to the logical queue specified by <seealso cref="destinationQueueName"/> by writing
/// a JSON serialied text to a file in the corresponding directory. The actual write operation is delayed until
/// the commit phase of the queue transaction unless we're non-transactional, in which case it is written immediately.
/// </summary>
public void Send(string destinationQueueName, TransportMessageToSend message, ITransactionContext context)
{
EnsureQueueInitialized(destinationQueueName);
var destinationDirectory = GetDirectoryForQueueNamed(destinationQueueName);
var serializedMessage = Serialize(message);
var fileName = GetNextFileName();
var fullPath = Path.Combine(destinationDirectory, fileName);
Action commitAction = () => File.WriteAllText(fullPath, serializedMessage, FavoriteEncoding);
if (context.IsTransactional)
{
context.DoCommit += commitAction;
}
else
{
commitAction();
}
}
开发者ID:nls75,项目名称:Rebus,代码行数:26,代码来源:FileSystemMessageQueue.cs
示例9: CanEncryptStuff
public void CanEncryptStuff()
{
// arrange
var transportMessageToSend = new TransportMessageToSend
{
Headers = new Dictionary<string, object> { { "test", "blah!" } },
Label = "label",
Body = Encoding.UTF7.GetBytes("Hello world!"),
};
// act
transport.Send("test", transportMessageToSend, new NoTransaction());
// assert
var sentMessage = sender.SentMessage;
sentMessage.Headers.Count.ShouldBe(3);
sentMessage.Headers["test"].ShouldBe("blah!");
sentMessage.Label.ShouldBe("label");
sentMessage.Body.ShouldNotBe(Encoding.UTF7.GetBytes("Hello world!"));
sentMessage.Headers.ShouldContainKey(Headers.Encrypted);
sentMessage.Headers.ShouldContainKey(Headers.EncryptionSalt);
Console.WriteLine("iv: " + sentMessage.Headers[Headers.EncryptionSalt]);
Console.WriteLine(string.Join(", ", sentMessage.Body.Select(b => b.ToString())));
}
开发者ID:rasmuskl,项目名称:Rebus,代码行数:26,代码来源:TestRijndaelEncryptionTransportDecorator.cs
示例10: Send
public void Send(string destinationQueueName, TransportMessageToSend message, ITransactionContext context)
{
SentMessage = message;
}
开发者ID:rasmuskl,项目名称:Rebus,代码行数:4,代码来源:TestRijndaelEncryptionTransportDecorator.cs
示例11: ItsSymmetric
public void ItsSymmetric()
{
var toSend = new TransportMessageToSend
{
Label = Guid.NewGuid().ToString(),
Headers = new Dictionary<string, object>
{
{Guid.NewGuid().ToString(), Guid.NewGuid().ToString()}
},
Body = Guid.NewGuid().ToByteArray(),
};
transport.Send("test", toSend, new NoTransaction());
var sentMessage = sender.SentMessage;
var receivedTransportMessage = new ReceivedTransportMessage
{
Id = Guid.NewGuid().ToString(),
Label = sentMessage.Label,
Headers = sentMessage.Headers,
Body = sentMessage.Body
};
receiver.SetUpReceive(receivedTransportMessage);
var receivedMessage = transport.ReceiveMessage(new NoTransaction());
receivedMessage.Label.ShouldBe(toSend.Label);
var expectedHeaders = toSend.Headers.Clone();
receivedMessage.Headers.ShouldBe(expectedHeaders);
receivedMessage.Body.ShouldBe(toSend.Body);
}
开发者ID:rasmuskl,项目名称:Rebus,代码行数:32,代码来源:TestRijndaelEncryptionTransportDecorator.cs
示例12: Send
/// <summary>
/// Sends the specified <see cref="TransportMessageToSend"/> to the logical queue specified by <paramref name="destinationQueueName"/>.
/// What actually happens, is that a row is inserted into the messages table, setting the 'recipient' column to the specified
/// queue.
/// </summary>
public void Send(string destinationQueueName, TransportMessageToSend message, ITransactionContext context)
{
var connection = GetConnectionPossiblyFromContext(context);
try
{
using (var command = connection.CreateCommand())
{
command.CommandText = string.Format(@"insert into [{0}]
([recipient], [headers], [label], [body], [priority])
values (@recipient, @headers, @label, @body, @priority)",
messageTableName);
var label = message.Label ?? "(no label)";
log.Debug("Sending message with label {0} to {1}", label, destinationQueueName);
var priority = GetMessagePriority(message);
command.Parameters.Add("recipient", SqlDbType.NVarChar, 200).Value = destinationQueueName;
command.Parameters.Add("headers", SqlDbType.NVarChar, Max).Value = DictionarySerializer.Serialize(message.Headers);
command.Parameters.Add("label", SqlDbType.NVarChar, Max).Value = label;
command.Parameters.Add("body", SqlDbType.VarBinary, Max).Value = message.Body;
command.Parameters.Add("priority", SqlDbType.TinyInt, 1).Value = priority;
command.ExecuteNonQuery();
}
if (!context.IsTransactional)
{
commitAction(connection);
}
}
finally
{
if (!context.IsTransactional)
{
releaseConnection(connection);
}
}
}
开发者ID:JanRou,项目名称:Rebus,代码行数:45,代码来源:SqlServerMessageQueue.cs
示例13: Send
public void Send(string destinationQueueName, TransportMessageToSend message, ITransactionContext context)
{
try
{
if (!context.IsTransactional)
{
using (var model = GetConnection().CreateModel())
{
var headers = GetHeaders(model, message);
model.BasicPublish(ExchangeName, destinationQueueName,
headers,
message.Body);
}
}
else
{
var model = GetSenderModel(context);
model.BasicPublish(ExchangeName, destinationQueueName,
GetHeaders(model, message),
message.Body);
}
}
catch (Exception e)
{
ErrorOnConnection(e);
throw;
}
}
开发者ID:schourode,项目名称:Rebus,代码行数:29,代码来源:RabbitMqMessageQueue.cs
示例14: Send
public void Send(string destinationQueueName, TransportMessageToSend message, ITransactionContext context)
{
if (!context.IsTransactional)
{
var envelopeToSendImmediately = CreateEnvelope(message);
var backoffTimes = new[] { 1, 2, 5, 10, 10, 10, 10, 10, 20, 20, 20, 30, 30, 30, 30 }
.Select(seconds => TimeSpan.FromSeconds(seconds))
.ToArray();
new Retrier(backoffTimes)
.RetryOn<ServerBusyException>()
.RetryOn<MessagingCommunicationException>()
.RetryOn<TimeoutException>()
.TolerateInnerExceptionsAsWell()
.Do(() =>
{
using (var messageToSendImmediately = CreateBrokeredMessage(envelopeToSendImmediately))
{
GetClientFor(destinationQueueName).Send(messageToSendImmediately);
}
});
return;
}
// if the batch is null, we're doing tx send outside of a message handler - this means
// that we must initialize the collection of messages to be sent
if (context[AzureServiceBusMessageBatch] == null)
{
context[AzureServiceBusMessageBatch] = new List<Tuple<string, Envelope>>();
context.DoCommit += () => DoCommit(context);
}
var envelope = CreateEnvelope(message);
var messagesToSend = (List<Tuple<string, Envelope>>)context[AzureServiceBusMessageBatch];
messagesToSend.Add(Tuple.Create(destinationQueueName, envelope));
}
开发者ID:rlarno,项目名称:Rebus,代码行数:40,代码来源:AzureServiceBusMessageQueue.cs
示例15: GetHeaders
IBasicProperties GetHeaders(IModel model, TransportMessageToSend message)
{
var props = model.CreateBasicProperties();
if (message.Headers != null)
{
props.Headers = message.Headers.ToDictionary(e => e.Key,
e => Encoding.GetBytes(e.Value));
if (message.Headers.ContainsKey(Headers.ReturnAddress))
{
props.ReplyTo = message.Headers[Headers.ReturnAddress];
}
}
props.MessageId = Guid.NewGuid().ToString();
return props;
}
开发者ID:ssboisen,项目名称:Rebus,代码行数:18,代码来源:RabbitMqMessageQueue.cs
示例16: Send
public void Send(string destinationQueueName, TransportMessageToSend message)
{
WithModel(m => m.BasicPublish(ExchangeName, destinationQueueName,
GetHeaders(m, message),
GetBody(message)));
}
开发者ID:ssboisen,项目名称:Rebus,代码行数:6,代码来源:RabbitMqMessageQueue.cs
示例17: ItsSymmetric
public void ItsSymmetric(int howManyGuidsToSend)
{
EnableEncryption();
EnableCompression();
var semiRandomBytes = Enumerable
.Repeat(Guid.NewGuid(), howManyGuidsToSend)
.SelectMany(guid => guid.ToByteArray())
.ToArray();
var someCustomHeaders =
new Dictionary<string, object>
{
{"some random header", Guid.NewGuid().ToString()},
{"another random header", Guid.NewGuid().ToString()}
};
var messageToSend =
new TransportMessageToSend
{
Label = Guid.NewGuid().ToString(),
Headers = someCustomHeaders,
Body = semiRandomBytes
};
transport.Send("test", messageToSend, new NoTransaction());
var wireMessage = sender.SentMessage;
var receivedTransportMessage = wireMessage.ToReceivedTransportMessage();
receiver.SetUpReceive(receivedTransportMessage);
var receivedMessage = transport.ReceiveMessage(new NoTransaction());
Console.WriteLine(@"
Transport message to send:
headers: {1}
body size: {0}
Wire transport message:
headers: {3}
body size: {2}
Received transport message:
headers: {5}
body size: {4}
",
messageToSend.Body.Length,
FormatHeaders(messageToSend.Headers),
wireMessage.Body.Length,
FormatHeaders(wireMessage.Headers),
receivedMessage.Body.Length,
FormatHeaders(receivedMessage.Headers));
receivedMessage.Label.ShouldBe(messageToSend.Label);
var expectedHeaders = messageToSend.Headers.Clone();
receivedMessage.Headers.ShouldBe(expectedHeaders);
receivedMessage.Body.ShouldBe(messageToSend.Body);
}
开发者ID:JanRou,项目名称:Rebus,代码行数:59,代码来源:TestEncryptionAndCompressionTransportDecorator.cs
示例18: EnsureInitialized
void EnsureInitialized(TransportMessageToSend message, string queueName)
{
// don't create recipient queue if multicasting
if (message.Headers.ContainsKey(Headers.Multicast))
{
message.Headers.Remove(Headers.Multicast);
return;
}
if (initializedQueues.Contains(queueName)) return;
lock (initializedQueues)
{
if (initializedQueues.Contains(queueName)) return;
InitializeLogicalQueue(queueName);
initializedQueues.Add(queueName);
}
}
开发者ID:rasmuskl,项目名称:Rebus,代码行数:19,代码来源:RabbitMqMessageQueue.cs
示例19: GetHeaders
static IBasicProperties GetHeaders(IModel modelToUse, TransportMessageToSend message)
{
var props = modelToUse.CreateBasicProperties();
if (message.Headers != null)
{
props.Headers = message.Headers
.ToHashtable(kvp => kvp.Key, kvp => PossiblyEncode(kvp.Value));
if (message.Headers.ContainsKey(Headers.ReturnAddress))
{
props.ReplyTo = (string)message.Headers[Headers.ReturnAddress];
}
}
props.MessageId = Guid.NewGuid().ToString();
props.SetPersistent(true);
return props;
}
开发者ID:rasmuskl,项目名称:Rebus,代码行数:20,代码来源:RabbitMqMessageQueue.cs
示例20: GetHeaders
IBasicProperties GetHeaders(IModel modelToUse, TransportMessageToSend message)
{
var props = modelToUse.CreateBasicProperties();
var persistentMessage = true;
if (message.Headers != null)
{
props.Headers = message.Headers
.ToHashtable(kvp => kvp.Key, kvp => PossiblyEncode(kvp.Value));
if (message.Headers.ContainsKey(Headers.MessageId))
{
// Not sure if message-id is always an string, so let's convert
// whatever the user specified to string and move on. (pruiz)
props.MessageId = Convert.ToString(message.Headers[Headers.MessageId]);
}
if (message.Headers.ContainsKey(Headers.ReturnAddress))
{
props.ReplyTo = (string)message.Headers[Headers.ReturnAddress];
}
if (message.Headers.ContainsKey(Headers.TimeToBeReceived))
{
var timeToBeReceived = message.Headers[Headers.TimeToBeReceived] as string;
if (timeToBeReceived == null)
{
throw new ArgumentException(
string.Format(
"Message header contains the {0} header, but the value is {1} and not a string as expected!",
Headers.TimeToBeReceived, message.Headers[Headers.TimeToBeReceived]));
}
try
{
var timeSpan = TimeSpan.Parse(timeToBeReceived);
var milliseconds = (int)timeSpan.TotalMilliseconds;
if (milliseconds <= 0)
{
throw new ArgumentException(
string.Format(
"Cannot set TTL message expiration to {0} milliseconds! Please specify a positive value!",
milliseconds));
}
props.Expiration = milliseconds.ToString();
}
catch (Exception e)
{
throw new FormatException(string.Format(
"Could not set TTL message expiration on message - apparently, '{0}' is not a valid TTL TimeSpan",
timeToBeReceived), e);
}
}
if (message.Headers.ContainsKey(InternalHeaders.MessageDurability))
{
var durableMessages = (message.Headers[InternalHeaders.MessageDurability] ?? "").ToString();
bool result;
if (bool.TryParse(durableMessages, out result))
{
persistentMessage = result;
}
else
{
throw new ArgumentException(
string.Format("Could not parse the value '{0}' from the '{1}' header into a proper bool",
durableMessages, InternalHeaders.MessageDurability));
}
}
}
// If not already set, specify a unique message's Id.
if (string.IsNullOrWhiteSpace(props.MessageId)) props.MessageId = Guid.NewGuid().ToString();
props.SetPersistent(persistentMessage);
return props;
}
开发者ID:jasonmueller,项目名称:Rebus,代码行数:80,代码来源:RabbitMqMessageQueue.cs
注:本文中的TransportMessageToSend类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论