当前位置: 首页>>代码示例>>C#>>正文


C# SQS.AmazonSQSClient类代码示例

本文整理汇总了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
                });
            }
        }
开发者ID:expectomas,项目名称:EventSparkz,代码行数:30,代码来源:AmazonConnection.cs

示例2: SQSHandeler

 public SQSHandeler(BasicAWSCredentials amazonCredentials, AmazonSQSClient sqsClient)
 {
     if (amazonCredentials != null && sqsClient != null) {
         this.amazonCredentials = amazonCredentials;
         this.sqsClient = sqsClient;
     }
 }
开发者ID:tyh24647,项目名称:Assignment_8_v2,代码行数:7,代码来源:SQSHandeler.cs

示例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);
             }
         }
     }
 }
开发者ID:pierskarsenbarg,项目名称:sqs-demo,代码行数:31,代码来源:QueueReceiverHelper.cs

示例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;
        }
开发者ID:iancooper,项目名称:Paramore,代码行数:29,代码来源:SqsQueuedRetriever.cs

示例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));
        }  
开发者ID:jrolstad,项目名称:Simple.Messaging,代码行数:30,代码来源:AmazonSqsMessageQueueDetailFactoryTests.cs

示例6: DeleteQueueByQueueUrl

 public static void DeleteQueueByQueueUrl(string queueUrl)
 {
     using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
     {
         client.DeleteQueue(queueUrl);
     }
 }
开发者ID:korz,项目名称:IntroductionToAmazonAws,代码行数:7,代码来源:Repository.cs

示例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;
        }
开发者ID:EdsonF,项目名称:log4net.aws,代码行数:30,代码来源:SQSAppender.cs

示例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;
 }
开发者ID:trheming,项目名称:LocationReporter,代码行数:9,代码来源:AmazonSqsClient.cs

示例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);
        }
开发者ID:modulexcite,项目名称:2015-Slides-and-Demos,代码行数:9,代码来源:Program.cs

示例10: DeleteQueue

 public virtual void DeleteQueue(AmazonSQSClient sqsClient, string queueUrl)
 {
     var deleteQueueRequest = new DeleteQueueRequest
     {
         QueueUrl = queueUrl
     };
     // Delete the queue
     sqsClient.DeleteQueue(deleteQueueRequest);
 }
开发者ID:jfaerman,项目名称:devonaws-labs-csharp,代码行数:9,代码来源:SolutionCode.cs

示例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);
			};
		}
开发者ID:Clancey,项目名称:aws-sdk-net,代码行数:11,代码来源:SQS_SampleViewController.cs

示例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;
            }
        }
开发者ID:korz,项目名称:IntroductionToAmazonAws,代码行数:14,代码来源:Repository.cs

示例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;
        }
开发者ID:jfaerman,项目名称:devonaws-labs-csharp,代码行数:14,代码来源:SolutionCode.cs

示例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);
                }
            }
        }
开发者ID:korz,项目名称:IntroductionToAmazonAws,代码行数:14,代码来源:Repository.cs

示例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);
            }
        }
开发者ID:igormoochnick,项目名称:EndToEndDistributedAppAws,代码行数:50,代码来源:WorkerRole.cs


注:本文中的Amazon.SQS.AmazonSQSClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。