本文整理汇总了C#中Amazon.SQS.AmazonSQSClient.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonSQSClient.SendMessage方法的具体用法?C# AmazonSQSClient.SendMessage怎么用?C# AmazonSQSClient.SendMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.SQS.AmazonSQSClient
的用法示例。
在下文中一共展示了AmazonSQSClient.SendMessage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteToQueue
static void WriteToQueue(AWSCredentials credentials)
{
AmazonSQSClient client = new AmazonSQSClient(credentials, RegionEndpoint.USEast1);
string message = "my message";
string queueUrl = "https://sqs.us-east-1.amazonaws.com/025631894481/aws-talk";
SendMessageResponse sendMessageResponse = client.SendMessage(queueUrl, message);
}
示例2: sendPosition
public bool sendPosition(string latitude, string longitude)
{
AmazonSQSClient sqsClient = new AmazonSQSClient(Amazon.RegionEndpoint.USEast1);
Amazon.SQS.Model.SendMessageRequest request = new Amazon.SQS.Model.SendMessageRequest();
request.QueueUrl = SQS_URL_STRING;
request.MessageBody = "lat: " + latitude + " lon: " + longitude;
sqsClient.SendMessage(request);
return true;
}
示例3: SqsActor
public SqsActor ()
{
Receive<string> (x => {
var sqs_url = Environment.GetEnvironmentVariable("sqs_url", EnvironmentVariableTarget.Process);
var config = new AmazonSQSConfig();
config.ServiceURL = sqs_url;
var creds = new StoredProfileAWSCredentials();
var client = new AmazonSQSClient(creds, config);
var msg = x + " and what " + Guid.NewGuid().ToString();
var queue_url = Environment.GetEnvironmentVariable("queue_url", EnvironmentVariableTarget.Process);
var request = new Amazon.SQS.Model.SendMessageRequest(queue_url, msg);
client.SendMessage(request);
Sender.Tell(string.Format("done : [{0}]", msg ));
});
}
示例4: SQSSendMessage
public static void SQSSendMessage()
{
#region SQSSendMessage
var client = new AmazonSQSClient();
var request = new SendMessageRequest
{
DelaySeconds = (int)TimeSpan.FromSeconds(5).TotalSeconds,
MessageAttributes = new Dictionary<string, MessageAttributeValue>
{
{
"MyNameAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "John Doe" }
},
{
"MyAddressAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "123 Main St." }
},
{
"MyRegionAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "Any Town, United States" }
}
},
MessageBody = "John Doe customer information.",
QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue"
};
var response = client.SendMessage(request);
Console.WriteLine("For message ID '" + response.MessageId + "':");
Console.WriteLine(" MD5 of message attributes: " +
response.MD5OfMessageAttributes);
Console.WriteLine(" MD5 of message body: " + response.MD5OfMessageBody);
#endregion
Console.ReadLine();
}
示例5: Post
// POST /api/echo
public void Post(string message)
{
// AWS: Get instance public address
string myAddress = HttpContext.Current.Request.Url.Authority;
try
{
myAddress = Encoding.ASCII.GetString(new WebClient().DownloadData("http://169.254.169.254/latest/meta-data/public-hostname"));
}
catch
{
}
var messageJob = new JsonObject();
messageJob["message"] = message;
messageJob["sender"] = myAddress;
// AWS SQS Client
var sqsClient = new AmazonSQSClient();
SendMessageRequest request = new SendMessageRequest()
.WithQueueUrl("https://queue.amazonaws.com/******/codeCampDemo")
.WithMessageBody(messageJob.ToString());
sqsClient.SendMessage(request);
}
示例6: PostToQueue
public virtual void PostToQueue(AmazonSQSClient sqsClient, string queueUrl, string messageText)
{
// Create the request
var sendMessageRequest = new SendMessageRequest
{
MessageBody = messageText,
QueueUrl = queueUrl
};
//Send message to queue
sqsClient.SendMessage(sendMessageRequest);
}
示例7: Main
public static void Main(string[] args)
{
IAmazonSQS sqs = new AmazonSQSClient(RegionEndpoint.USWest2);
try
{
Console.WriteLine("===========================================");
Console.WriteLine("Getting Started with Amazon SQS");
Console.WriteLine("===========================================\n");
//Creating a queue
Console.WriteLine("Create a queue called MyQueue.\n");
CreateQueueRequest sqsRequest = new CreateQueueRequest();
sqsRequest.QueueName = "MyQueue";
CreateQueueResponse createQueueResponse = sqs.CreateQueue(sqsRequest);
String myQueueUrl;
myQueueUrl = createQueueResponse.QueueUrl;
//Confirming the queue exists
ListQueuesRequest listQueuesRequest = new ListQueuesRequest();
ListQueuesResponse listQueuesResponse = sqs.ListQueues(listQueuesRequest);
Console.WriteLine("Printing list of Amazon SQS queues.\n");
foreach (String queueUrl in listQueuesResponse.QueueUrls)
{
Console.WriteLine(" QueueUrl: {0}", queueUrl);
}
Console.WriteLine();
//Sending a message
Console.WriteLine("Sending a message to MyQueue.\n");
SendMessageRequest sendMessageRequest = new SendMessageRequest();
sendMessageRequest.QueueUrl = myQueueUrl; //URL from initial queue creation
sendMessageRequest.MessageBody = "This is my message text.";
sqs.SendMessage(sendMessageRequest);
//Receiving a message
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
receiveMessageRequest.QueueUrl = myQueueUrl;
ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);
Console.WriteLine("Printing received message.\n");
foreach (Message message in receiveMessageResponse.Messages)
{
Console.WriteLine(" Message");
Console.WriteLine(" MessageId: {0}", message.MessageId);
Console.WriteLine(" ReceiptHandle: {0}", message.ReceiptHandle);
Console.WriteLine(" MD5OfBody: {0}", message.MD5OfBody);
Console.WriteLine(" Body: {0}", message.Body);
foreach (KeyValuePair<string, string> entry in message.Attributes)
{
Console.WriteLine(" Attribute");
Console.WriteLine(" Name: {0}", entry.Key);
Console.WriteLine(" Value: {0}", entry.Value);
}
}
String messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle;
//Deleting a message
Console.WriteLine("Deleting the message.\n");
DeleteMessageRequest deleteRequest = new DeleteMessageRequest();
deleteRequest.QueueUrl = myQueueUrl;
deleteRequest.ReceiptHandle = messageRecieptHandle;
sqs.DeleteMessage(deleteRequest);
}
catch (AmazonSQSException ex)
{
Console.WriteLine("Caught Exception: " + ex.Message);
Console.WriteLine("Response Status Code: " + ex.StatusCode);
Console.WriteLine("Error Code: " + ex.ErrorCode);
Console.WriteLine("Error Type: " + ex.ErrorType);
Console.WriteLine("Request ID: " + ex.RequestId);
}
Console.WriteLine("Press Enter to continue...");
Console.Read();
}
示例8: Requeue
/// <summary>
/// Requeues the specified message.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="delayMilliseconds">Number of milliseconds to delay delivery of the message.</param>
public void Requeue(Message message, int delayMilliseconds)
{
try
{
Reject(message, false);
using (var client = new AmazonSQSClient())
{
_logger.InfoFormat("SqsMessageConsumer: requeueing the message {0}", message.Id);
message.Header.Bag.Remove("ReceiptHandle");
var request = new SendMessageRequest(_queueUrl, JsonConvert.SerializeObject(message))
{
DelaySeconds = (int)TimeSpan.FromMilliseconds(delayMilliseconds).TotalSeconds
};
client.SendMessage(request);
}
_logger.InfoFormat("SqsMessageConsumer: requeued the message {0}", message.Id);
}
catch (Exception exception)
{
_logger.ErrorException("SqsMessageConsumer: Error purging queue {0}", exception, _queueUrl);
throw;
}
}
示例9: Main
public static void Main(string[] args)
{
var sqs = new AmazonSQSClient();
try
{
Console.WriteLine("===========================================");
Console.WriteLine("Getting Started with Amazon SQS");
Console.WriteLine("===========================================\n");
//Confirming the queue exists
var listQueuesRequest = new ListQueuesRequest();
var listQueuesResponse = sqs.ListQueues(listQueuesRequest);
string myQueueUrl = string.Empty;
Console.WriteLine("Printing list of Amazon SQS queues.\n");
bool queueExists = false;
if (listQueuesResponse.QueueUrls != null)
{
foreach (String queueUrl in listQueuesResponse.QueueUrls)
{
Console.WriteLine(" QueueUrl: {0}", queueUrl);
if (queueUrl.EndsWith("MyQueue"))
{
queueExists = true;
myQueueUrl = queueUrl;
break;
}
}
}
Console.WriteLine();
if (!queueExists)
{
//Creating a queue
Console.WriteLine("Create a queue called MyQueue.\n");
var sqsRequest = new CreateQueueRequest { QueueName = "MyQueue" };
var createQueueResponse = sqs.CreateQueue(sqsRequest);
myQueueUrl = createQueueResponse.QueueUrl;
}
//Sending a message
Console.WriteLine("Sending a message to MyQueue.\n");
var sendMessageRequest = new SendMessageRequest
{
QueueUrl = myQueueUrl, //URL from initial queue creation
MessageBody = string.Format("ATL MEETUP - This is my message text from server - {0}",System.Environment.MachineName)
};
sqs.SendMessage(sendMessageRequest);
////Receiving a message
//var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = myQueueUrl };
//var receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);
//if (receiveMessageResponse.Messages != null)
//{
// Console.WriteLine("Printing received message.\n");
// foreach (var message in receiveMessageResponse.Messages)
// {
// Console.WriteLine(" Message");
// if (!string.IsNullOrEmpty(message.MessageId))
// {
// Console.WriteLine(" MessageId: {0}", message.MessageId);
// }
// if (!string.IsNullOrEmpty(message.ReceiptHandle))
// {
// Console.WriteLine(" ReceiptHandle: {0}", message.ReceiptHandle);
// }
// if (!string.IsNullOrEmpty(message.MD5OfBody))
// {
// Console.WriteLine(" MD5OfBody: {0}", message.MD5OfBody);
// }
// if (!string.IsNullOrEmpty(message.Body))
// {
// Console.WriteLine(" Body: {0}", message.Body);
// }
// foreach (string attributeKey in message.Attributes.Keys)
// {
// Console.WriteLine(" Attribute");
// Console.WriteLine(" Name: {0}", attributeKey);
// var value = message.Attributes[attributeKey];
// Console.WriteLine(" Value: {0}", string.IsNullOrEmpty(value) ? "(no value)" : value);
// }
// }
// var messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle;
// //Deleting a message
// Console.WriteLine("Deleting the message.\n");
// var deleteRequest = new DeleteMessageRequest { QueueUrl = myQueueUrl, ReceiptHandle = messageRecieptHandle };
// sqs.DeleteMessage(deleteRequest);
//}
}
catch (AmazonSQSException ex)
{
Console.WriteLine("Caught Exception: " + ex.Message);
Console.WriteLine("Response Status Code: " + ex.StatusCode);
Console.WriteLine("Error Code: " + ex.ErrorCode);
Console.WriteLine("Error Type: " + ex.ErrorType);
//.........这里部分代码省略.........
示例10: QueueMessage
private static String QueueMessage()
{
using (AmazonSQSClient client = new AmazonSQSClient(
ConfigurationManager.AppSettings["AWSAccessKey"],
ConfigurationManager.AppSettings["AWSSecretAccessKey"]))
{
SendMessageRequest request = new SendMessageRequest();
request.MessageBody = Guid.NewGuid().ToString();
request.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
SendMessageResponse response = client.SendMessage(request);
return response.SendMessageResult.MessageId;
}
}
示例11: EnqueueByQueueUrl
public static void EnqueueByQueueUrl(string queueUrl, string message)
{
using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
{
var request = new SendMessageRequest()
{
QueueUrl = queueUrl,
MessageBody = message,
};
client.SendMessage(request);
}
}
示例12: EnqueueListByQueueUrl
public static void EnqueueListByQueueUrl(string queueUrl, IEnumerable<string> messages)
{
using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
{
foreach (var message in messages)
{
var request = new SendMessageRequest()
{
QueueUrl = queueUrl,
MessageBody = message,
};
client.SendMessage(request);
}
}
}