本文整理汇总了C#中Amazon.SQS.AmazonSQSClient类的典型用法代码示例。如果您正苦于以下问题:C# AmazonSQSClient类的具体用法?C# AmazonSQSClient怎么用?C# AmazonSQSClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonSQSClient类属于Amazon.SQS命名空间,在下文中一共展示了AmazonSQSClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AmazonConnection
public AmazonConnection(TypeOfMsg requestMsgType)
{
pollingMsg = requestMsgType;
objClient = new AmazonSQSClient(AccessKeyId, SecretAccessKey);
CreateQueueResponse queueResponse = new CreateQueueResponse();
//Request existing queues
ListQueuesResult allQueues = requestListOfQueuesInSQS();
bool eventSparkzQueueListExists = false;
foreach (string queueURL in allQueues.QueueUrl)
{
if (queueURL.Equals(QueueURLString))
{
eventSparkzQueueListExists = true;
}
}
if (!eventSparkzQueueListExists)
{
queueResponse = objClient.CreateQueue(new CreateQueueRequest()
{
QueueName
= EventSparkzQueueName
});
}
}
示例2: SQSHandeler
public SQSHandeler(BasicAWSCredentials amazonCredentials, AmazonSQSClient sqsClient)
{
if (amazonCredentials != null && sqsClient != null) {
this.amazonCredentials = amazonCredentials;
this.sqsClient = sqsClient;
}
}
示例3: DoWork
public void DoWork()
{
var credentials = new BasicAWSCredentials(ConfigurationManager.AppSettings["AccessKey"], ConfigurationManager.AppSettings["SecretKey"]);
_sqsClient = new AmazonSQSClient(credentials, RegionEndpoint.EUWest1);
Console.WriteLine("Number of messages at once");
int numberOfMessages;
int.TryParse(Console.ReadLine(), out numberOfMessages);
var running = true;
while (running)
{
var messageList = GetMessageFromQueue(numberOfMessages);
Console.WriteLine("Number of messages: " + messageList.Count);
if (messageList.Count == 0)
{
Thread.Sleep(5000);
}
Console.WriteLine();
foreach (var message in messageList)
{
Console.WriteLine("Message: " + message.Body);
Console.WriteLine("Receipt Handle: " + message.ReceiptHandle);
Console.WriteLine("Delete?");
var readLine = Console.ReadLine();
var delete = readLine != null ? readLine.ToLower() : "n";
if (delete == "y")
{
DeleteMessageFromQueue(message.ReceiptHandle);
}
}
}
}
示例4: GetMessage
public async Task<Amazon.SQS.Model.Message> GetMessage(string queueName, int timeoutInMilliseconds, int numberOfCacheableMessages)
{
Amazon.SQS.Model.Message message = null;
if (_queue.ContainsKey(queueName) && _queue[queueName].TryDequeue(out message)) return message;
var request = new ReceiveMessageRequest(queueName)
{
MaxNumberOfMessages = numberOfCacheableMessages,
WaitTimeSeconds = (int)TimeSpan.FromMilliseconds(timeoutInMilliseconds).TotalSeconds
};
using (var client = new AmazonSQSClient(_credentials))
{
var response = await client.ReceiveMessageAsync(request);
if (response.HttpStatusCode != HttpStatusCode.OK) return message;
if (response.ContentLength == 0) return message;
if (!response.Messages.Any()) return message;
AddToQueue(queueName, response.Messages);
if(_queue.ContainsKey(queueName))
_queue[queueName].TryDequeue(out message);
}
return message;
}
示例5: When_obtaining_details_on_a_message_queue
public void When_obtaining_details_on_a_message_queue(string queueName, bool exists)
{
// Arrange
var client = new AmazonSQSClient("access key", "secret key");
if (exists)
{
client.CreateQueue(new CreateQueueRequest().WithQueueName(queueName));
}
else
{
var response = client.ListQueues(new ListQueuesRequest().WithQueueNamePrefix(queueName));
if (response.ListQueuesResult.QueueUrl.Any())
{
client.DeleteQueue(new DeleteQueueRequest().WithQueueUrl(response.ListQueuesResult.QueueUrl.First()));
}
}
Thread.Sleep(2000); // Give the queues some time to spin up
var factory = new AmazonSqsMessageQueueDetailFactory(client);
// Act
var result = factory.Build<TestMessage>(queueName);
// Assert
Assert.That(result.Uri, Is.StringContaining(queueName));
Assert.That(result.Exists, Is.EqualTo(exists));
}
示例6: DeleteQueueByQueueUrl
public static void DeleteQueueByQueueUrl(string queueUrl)
{
using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
{
client.DeleteQueue(queueUrl);
}
}
示例7: InitializeQueue
private AmazonSQSClient InitializeQueue()
{
var client = new AmazonSQSClient(Utility.GetRegionEndpoint());
ListQueuesRequest listQueuesRequest = new ListQueuesRequest
{
QueueNamePrefix = QueueName
};
var listQueuesResponse = client.ListQueues(listQueuesRequest);
bool found = listQueuesResponse.ListQueuesResult.QueueUrls.Any(s => s == QueueName);
if (found == false)
{
var createQueueResponse = client.CreateQueue(new CreateQueueRequest
{
QueueName = QueueName
});
QueueUrl = createQueueResponse.CreateQueueResult.QueueUrl;
}
else
{
QueueUrl = client.GetQueueUrl(
new GetQueueUrlRequest
{
QueueName = _queueName
}
).GetQueueUrlResult.QueueUrl;
}
return client;
}
示例8: 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;
}
示例9: 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);
}
示例10: DeleteQueue
public virtual void DeleteQueue(AmazonSQSClient sqsClient, string queueUrl)
{
var deleteQueueRequest = new DeleteQueueRequest
{
QueueUrl = queueUrl
};
// Delete the queue
sqsClient.DeleteQueue(deleteQueueRequest);
}
示例11: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
CreateQueue.TouchUpInside += delegate(object sender, EventArgs e) {
var sqsClient = new Amazon.SQS.AmazonSQSClient (ACCESS_KEY, SECRET_KEY, Amazon.RegionEndpoint.EUWest1);
var request = new Amazon.SQS.Model.CreateQueueRequest ();
request.QueueName = "newQueue";
var response = sqsClient.CreateQueue (request);
CreateQueueResults.Text = String.Format("Queue created at {0}.", response.QueueUrl);
};
}
示例12: CreateQueue
public static string CreateQueue(string name)
{
using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
{
var request = new CreateQueueRequest
{
QueueName = name
};
var response = client.CreateQueue(request);
return response.QueueUrl;
}
}
示例13: CreateQueue
public virtual string CreateQueue(AmazonSQSClient sqsClient, string queueName)
{
string queueUrl;
// Create the request
var createQueueRequest = new CreateQueueRequest {QueueName = queueName};
// Submit the request
CreateQueueResponse createQueueResponse = sqsClient.CreateQueue(createQueueRequest);
// Return the URL for the newly created queue
queueUrl = createQueueResponse.QueueUrl;
return queueUrl;
}
示例14: DeleteAllQueues
public static void DeleteAllQueues()
{
using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
{
var response = client.ListQueues(new ListQueuesRequest());
foreach (var queueUrl in response.QueueUrls)
{
PurgeQueueByQueueUrl(queueUrl);
client.DeleteQueue(queueUrl);
}
}
}
示例15: Main
static void Main(string[] args)
{
// AWS: Get instance public address
string myId = "localhost";
try
{
myId = Encoding.ASCII.GetString(new WebClient().DownloadData("http://169.254.169.254/latest/meta-data/public-hostname"));
}
catch
{
}
// AWS SQS Client
var sqsClient = new AmazonSQSClient();
while (true)
{
// Get the next message
ReceiveMessageRequest request = new ReceiveMessageRequest()
.WithQueueUrl("https://queue.amazonaws.com/*****/codeCampDemo")
.WithMaxNumberOfMessages(1);
var response = sqsClient.ReceiveMessage(request);
foreach (var retrievedMessage in response.ReceiveMessageResult.Message)
{
var messageJson = JsonValue.Parse(retrievedMessage.Body);
var message = messageJson["message"].ReadAs<string>();
Console.WriteLine(message);
message = "Echo: " + message;
string address = string.Format("http://{0}", messageJson["sender"].ReadAs<string>());
var connection = new HubConnection(address);
connection.Start().Wait();
IHubProxy pongHub = connection.CreateProxy("MvcWebRole1.Hubs.EchoHub");
pongHub.Invoke("DoUpdateMessage", message, myId).Wait();
//Process the message and then delete the message
DeleteMessageRequest deleteRequest = new DeleteMessageRequest()
.WithQueueUrl("https://queue.amazonaws.com/******/codeCampDemo")
.WithReceiptHandle(retrievedMessage.ReceiptHandle);
sqsClient.DeleteMessage(deleteRequest);
}
Thread.Sleep(1000);
}
}