本文整理汇总了C#中TransportMessageToSend类的典型用法代码示例。如果您正苦于以下问题:C# TransportMessageToSend类的具体用法?C# TransportMessageToSend怎么用?C# TransportMessageToSend使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransportMessageToSend类属于命名空间,在下文中一共展示了TransportMessageToSend类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
示例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())));
}
示例10: Send
public void Send(string destinationQueueName, TransportMessageToSend message, ITransactionContext context)
{
SentMessage = message;
}
示例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);
}
示例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);
}
}
}
示例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;
}
}
示例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));
}
示例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;
}