本文整理汇总了C#中Factory.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Factory.SendMessage方法的具体用法?C# Factory.SendMessage怎么用?C# Factory.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Factory
的用法示例。
在下文中一共展示了Factory.SendMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
/// <summary>
/// Sends a new message to Amazon SQS using
/// the specified queue URL. The message size
/// limit is 256kb.
/// </summary>
/// <param name="queueUrl">The sqs queue endpoint to send the message to.</param>
/// <param name="message">The message to send via SQS.</param>
public static Amazon.SQS.Model.SendMessageResponse Send(string queueUrl, string message)
{
// Check that there is content for the message.
if (string.IsNullOrEmpty(message))
throw new ArgumentException("The message cannot be nothing!");
// Check that the size of the message is okay.
int messageSize = System.Text.ASCIIEncoding.Unicode.GetByteCount(message);
if ((messageSize / 1000) >= 256)
throw new ArgumentException("The message size cannot be larger than 256kb!");
// Send the message to Amazon.
Amazon.SQS.Model.SendMessageResponse response = new Amazon.SQS.Model.SendMessageResponse();
using (Amazon.SQS.IAmazonSQS client = new Factory().SQSClient())
{
Amazon.SQS.Model.SendMessageRequest request = new Amazon.SQS.Model.SendMessageRequest()
{
MessageBody = message,
QueueUrl = queueUrl
};
response = client.SendMessage(request);
}
return response;
}