コード例 #1
0
        private SqsQueueDefinition CreateQueue(SqsQueueName queueName, int?visibilityTimeoutSeconds = null,
                                               int?receiveWaitTimeSeconds     = null, bool?disasbleBuffering = null,
                                               SqsRedrivePolicy redrivePolicy = null)
        {
            SqsQueueDefinition queueDefinition = null;

            var request = new CreateQueueRequest
            {
                QueueName  = queueName.AwsQueueName,
                Attributes = new Dictionary <string, string>
                {
                    {
                        QueueAttributeName.ReceiveMessageWaitTimeSeconds,
                        TimeSpan.FromSeconds(receiveWaitTimeSeconds ?? DefaultReceiveWaitTime)
                        .TotalSeconds
                        .ToString(CultureInfo.InvariantCulture)
                    },
                    {
                        QueueAttributeName.VisibilityTimeout,
                        TimeSpan.FromSeconds(visibilityTimeoutSeconds ?? DefaultVisibilityTimeout)
                        .TotalSeconds
                        .ToString(CultureInfo.InvariantCulture)
                    },
                    {
                        QueueAttributeName.MessageRetentionPeriod,
                        (QueueNames.IsTempQueue(queueName.QueueName)
                            ? SqsQueueDefinition.DefaultTempQueueRetentionSeconds
                            : SqsQueueDefinition.DefaultPermanentQueueRetentionSeconds).ToString(CultureInfo.InvariantCulture)
                    }
                }
            };

            if (redrivePolicy != null)
            {
                var json = redrivePolicy.ToJson();
                request.Attributes.Add(QueueAttributeName.RedrivePolicy, json);
            }

            try
            {
                var createResponse = SqsClient.CreateQueue(request);

                // Note - must go fetch the attributes from the server after creation, as the request attributes do not include
                // anything assigned by the server (i.e. the ARN, etc.).
                queueDefinition = GetQueueDefinition(queueName, createResponse.QueueUrl);

                queueDefinition.DisableBuffering = disasbleBuffering ?? DisableBuffering;

                queueNameMap[queueDefinition.QueueName] = queueDefinition;
            }
            catch (QueueNameExistsException)
            {   // Queue exists with different attributes, instead of creating, alter those attributes to match what was requested
                queueDefinition = UpdateQueue(queueName, request.ToSetAttributesRequest(null), disasbleBuffering);
            }

            return(queueDefinition);
        }
コード例 #2
0
        /// <summary>
        /// 创建队列
        /// </summary>
        public async Task <CreateQueueResponse> CreateQueueAsync(CreateQueueRequest createQueueRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();
            string              urlPath          = HttpUtils.AddUrlPath("/v2/{project_id}/queues", urlParam);
            SdkRequest          request          = HttpUtils.InitSdkRequest(urlPath, "application/json", createQueueRequest);
            HttpResponseMessage response         = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerialize <CreateQueueResponse>(response));
        }
コード例 #3
0
        public void CreateQueue_WithNameContainingVariousInvalidChars_ShouldThrowAmazonSQSException(string queueName)
        {
            var sqsRequest = new CreateQueueRequest(queueName);

            var exception = Assert.Throws <AmazonSQSException>(() => _sqs.CreateQueue(sqsRequest));

            Assert.Contains("InvalidParameterValue", exception.ErrorCode);
            Assert.Equal(System.Net.HttpStatusCode.BadRequest, exception.StatusCode);
        }
コード例 #4
0
        /// <inheritdoc/>
        public Queue CreateQueue(CreateQueueRequest request)
        {
            var marshaller   = new CreateQueueRequestMarshaller();
            var unmarshaller = CreateQueueResponseUnmarshaller.Instance;

            var response = Invoke <CreateQueueRequest, CreateQueueResponse>(request, marshaller, unmarshaller);

            return(new Queue(response.QueueUrl.Substring(response.QueueUrl.LastIndexOf("/") + 1), this));
        }
コード例 #5
0
        /// <summary>
        ///     Creates the queue with the given name
        /// </summary>
        public void CreateQueue(string address)
        {
            m_log.Info("Creating queue {queueName} on region {regionEndpoint}", address, m_AmazonInternalSettings.AmazonSqsConfig.RegionEndpoint);

            var amazonSqsConfig = m_AmazonInternalSettings.AmazonSqsConfig;
            var awsCredentials  = m_AmazonInternalSettings.AmazonCredentialsFactory.Create();

            using (var client = new AmazonSQSClient(awsCredentials, amazonSqsConfig))
            {
                var queueName = GetQueueNameFromAddress(address);

                // Check if queue exists
                try
                {
                    var request = new GetQueueUrlRequest(queueName);
                    // See http://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SQS/TSQSGetQueueUrlRequest.html for options
                    var getQueueUrlTask = client.GetQueueUrlAsync(request);
                    AsyncHelpers.RunSync(() => getQueueUrlTask);
                    var getQueueUrlResponse = getQueueUrlTask.Result;

                    if (getQueueUrlResponse.HttpStatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception($"Could not check for existing queue '{queueName}' - got HTTP {getQueueUrlResponse.HttpStatusCode}");
                    }

                    var visibilityTimeout = ((int)m_AmazonInternalSettings.AmazonPeekLockDuration.PeekLockDuration.TotalSeconds).ToString(CultureInfo.InvariantCulture);

                    // See http://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SQS/TSQSSetQueueAttributesRequest.html for options
                    var setAttributesTask = client.SetQueueAttributesAsync(getQueueUrlResponse.QueueUrl, new Dictionary <string, string> {
                        ["VisibilityTimeout"] = visibilityTimeout
                    });
                    AsyncHelpers.RunSync(() => setAttributesTask);
                    var setAttributesResponse = setAttributesTask.Result;

                    if (setAttributesResponse.HttpStatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception($"Could not set attributes for queue '{queueName}' - got HTTP {setAttributesResponse.HttpStatusCode}");
                    }
                }
                catch (QueueDoesNotExistException)
                {
                    // See http://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SQS/TSQSCreateQueueRequest.html for options
                    var createQueueRequest = new CreateQueueRequest(queueName)
                    {
                        Attributes = { ["VisibilityTimeout"] = ((int)m_AmazonInternalSettings.AmazonPeekLockDuration.PeekLockDuration.TotalSeconds).ToString(CultureInfo.InvariantCulture) }
                    };
                    var task = client.CreateQueueAsync(createQueueRequest);
                    AsyncHelpers.RunSync(() => task);
                    var response = task.Result;

                    if (response.HttpStatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception($"Could not create queue '{queueName}' - got HTTP {response.HttpStatusCode}");
                    }
                }
            }
        }
コード例 #6
0
        public async Task <Queue> CreateQueueAsync(CreateQueueRequest request)
        {
            var marshaller   = new CreateQueueRequestMarshaller();
            var unmarshaller = CreateQueueResponseUnmarshaller.Instance;

            var response = await InvokeAsync <CreateQueueRequest, CreateQueueResponse>(request, marshaller, unmarshaller).ConfigureAwait(false);

            return(new Queue(response.QueueUrl.Substring(response.QueueUrl.LastIndexOf("/") + 1), this));
        }
コード例 #7
0
 public static CreateQueueResponse CreateAWSSQSQueue(string queueName)
 {
     using (IAmazonSQS sqs = new AmazonSQSClient(RegionEndpoint.USEast1))
     {
         Console.WriteLine("AWS SQS Queue Creation Started.....");
         var createQueueReq = new CreateQueueRequest(queueName);
         return(sqs.CreateQueueAsync(createQueueReq).Result);
     }
 }
コード例 #8
0
        private CreateQueueResponse CreateQueue(string queueName)
        {
            var sqsRequest          = new CreateQueueRequest(queueName);
            var createQueueResponse = _sqs.CreateQueue(sqsRequest);

            _queueUrl = createQueueResponse.QueueUrl;

            return(createQueueResponse);
        }
コード例 #9
0
        private void CreateDLQ(AmazonSQSClient sqsClient)
        {
            try
            {
                var request = new CreateQueueRequest(_subscription.RedrivePolicy.DeadlLetterQueueName.Value);

                var createDeadLetterQueueResponse = sqsClient.CreateQueueAsync(request).GetAwaiter().GetResult();

                var queueUrl = createDeadLetterQueueResponse.QueueUrl;

                if (!string.IsNullOrEmpty(queueUrl))
                {
                    //We need the ARN of the dead letter queue to configure the queue redrive policy, not the name
                    var attributesRequest = new GetQueueAttributesRequest
                    {
                        QueueUrl       = queueUrl,
                        AttributeNames = new List <string> {
                            "QueueArn"
                        }
                    };
                    var attributesResponse = sqsClient.GetQueueAttributesAsync(attributesRequest).GetAwaiter().GetResult();

                    if (attributesResponse.HttpStatusCode != HttpStatusCode.OK)
                    {
                        throw new InvalidOperationException($"Could not find ARN of DLQ, status: {attributesResponse.HttpStatusCode}");
                    }

                    _dlqARN = attributesResponse.QueueARN;
                }
                else
                {
                    throw new InvalidOperationException($"Could not find create DLQ, status: {createDeadLetterQueueResponse.HttpStatusCode}");
                }
            }
            catch (QueueDeletedRecentlyException ex)
            {
                //QueueDeletedRecentlyException - wait 30 seconds then retry
                //Although timeout is 60s, we could be partway through that, so apply Copernican Principle
                //and assume we are halfway through
                var error = $"Could not create queue {_subscription.ChannelName.Value} because {ex.Message} waiting 60s to retry";
                s_logger.LogError(ex, error);
                Thread.Sleep(TimeSpan.FromSeconds(30));
                throw new ChannelFailureException(error, ex);
            }
            catch (AmazonSQSException ex)
            {
                var error = $"Could not create queue {_queueUrl} subscribed to topic {_subscription.RoutingKey.Value} in region {_awsConnection.Region.DisplayName} because {ex.Message}";
                s_logger.LogError(ex, error);
                throw new InvalidOperationException(error, ex);
            }
            catch (HttpErrorResponseException ex)
            {
                var error = $"Could not create queue {_queueUrl} subscribed to topic {_subscription.RoutingKey.Value} in region {_awsConnection.Region.DisplayName} because {ex.Message}";
                s_logger.LogError(ex, error);
                throw new InvalidOperationException(error, ex);
            }
        }
コード例 #10
0
        /// <summary>
        /// Creates a new Message Queue on SQS and returns the queue url.
        /// </summary>
        /// <param name="queueName">The name of the new message queue.</param>
        /// <returns>The url of the new message queue.</returns>
        public string CreateMessageQueue(string queueName)
        {
            // Clean the queue name
            queueName = QueueNameRegex.Replace(queueName, "_");
            var createQueueRequest = new CreateQueueRequest().WithQueueName(queueName);
            var response           = this.CreateMessageQueue(createQueueRequest);

            return(response.CreateQueueResult.QueueUrl);
        }
コード例 #11
0
ファイル: AgQueueService.cs プロジェクト: masilver99/AgQueue
        public override async Task <CreateQueueResponse> CreateQueue(CreateQueueRequest request, ServerCallContext context)
        {
            // TODO: ensure the new queue name doesn't exist.
            var queueInfo = await this.internalApi.CreateQueue(request.QueueName);

            return(new CreateQueueResponse {
                QueueId = queueInfo.Id, QueueName = queueInfo.Name
            });
        }
コード例 #12
0
        public static void SQSQueueStandard()
        {
            Console.WriteLine("**********************************");
            Console.WriteLine("*******___Amazon SQS___***********");
            Console.WriteLine("**********************************\n");

            //------- Creating a SQS standard queue
            IAmazonSQS sqs = new AmazonSQSClient(RegionEndpoint.USEast1);

            var sqsRequest = new CreateQueueRequest
            {
                QueueName = "pradoqueue3"
            };

            var createQueueResponse = sqs.CreateQueueAsync(sqsRequest).Result;

            var myQueueUrl = createQueueResponse.QueueUrl; // Retrieving the queue URL

            //------- Retrieving all existing queues URL
            var listQueuesRequest  = new ListQueuesRequest();
            var listQueuesResponse = sqs.ListQueuesAsync(listQueuesRequest);

            Console.WriteLine("List of Amazon SQS Queues\n");
            foreach (var queue in listQueuesResponse.Result.QueueUrls)
            {
                Console.WriteLine($"QueueUrl: {queue}");
            }

            //------- Sending a message tho the created queue
            Console.WriteLine("Sending a message to the queue\n");
            var sqsMessageRequest = new SendMessageRequest
            {
                QueueUrl    = myQueueUrl,
                MessageBody = "Email information"
            };

            sqs.SendMessageAsync(sqsMessageRequest);

            Console.WriteLine("Finished sending message to the SQS queue\n");

            //------- Reading the message sended above
            Console.WriteLine("Reading messages from the queue\n");

            var receiveMessageRequest = new ReceiveMessageRequest();

            receiveMessageRequest.QueueUrl = myQueueUrl;

            var receiveMessageResponse = sqs.ReceiveMessageAsync(receiveMessageRequest);

            foreach (var message in receiveMessageResponse.Result.Messages)
            {
                Console.WriteLine(message.Body);  // Go to a method to process messages.
            }

            Console.ReadLine();
        }
コード例 #13
0
        static void SetupTopicAndQueue(Amazon.RegionEndpoint region)
        {
            long ticks = DateTime.Now.Ticks;

            // Setup SNS topic.
            s_snsClient = new AmazonSimpleNotificationServiceClient(region);
            s_sqsClient = new AmazonSQSClient(region);

            s_topicArn = s_snsClient.CreateTopic(new CreateTopicRequest
            {
                Name = "GlacierDownload-" + ticks
            }).TopicArn;

            WriteLogConsole("topicArn: " + s_topicArn);

            CreateQueueRequest createQueueRequest = new CreateQueueRequest();

            createQueueRequest.QueueName = "GlacierDownload-" + ticks;
            CreateQueueResponse createQueueResponse = s_sqsClient.CreateQueue(createQueueRequest);

            s_queueUrl = createQueueResponse.QueueUrl;

            WriteLogConsole("QueueURL: " + s_queueUrl);

            GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest();

            getQueueAttributesRequest.AttributeNames = new List <string> {
                "QueueArn"
            };
            getQueueAttributesRequest.QueueUrl = s_queueUrl;

            GetQueueAttributesResponse response = s_sqsClient.GetQueueAttributes(getQueueAttributesRequest);

            s_queueArn = response.QueueARN;
            WriteLogConsole("QueueArn: " + s_queueArn);

            // Setup the Amazon SNS topic to publish to the SQS queue.
            s_snsClient.Subscribe(new SubscribeRequest()
            {
                Protocol = "sqs",
                Endpoint = s_queueArn,
                TopicArn = s_topicArn
            });

            // Add the policy to the queue so SNS can send messages to the queue.
            var policy = SQS_POLICY.Replace("{TopicArn}", s_topicArn).Replace("{QuernArn}", s_queueArn);

            s_sqsClient.SetQueueAttributes(new SetQueueAttributesRequest()
            {
                QueueUrl   = s_queueUrl,
                Attributes = new Dictionary <string, string>
                {
                    { QueueAttributeName.Policy, policy }
                }
            });
        }
コード例 #14
0
        public virtual void CreateQueue(string queueName)
        {
            var client  = this.GetClient();
            var request = new CreateQueueRequest
            {
                QueueName = queueName,
            };

            var response = client.CreateQueue(request);
        }
コード例 #15
0
        /// <summary>
        /// Creates the queue with the given name
        /// </summary>
        public void CreateQueue(string address)
        {
            if (!_options.CreateQueues)
            {
                return;
            }

            _log.Info("Creating queue {queueName}", address);

            var queueName = GetQueueNameFromAddress(address);

            AsyncHelpers.RunSync(async() =>
            {
                // Check if queue exists
                try
                {
                    // See http://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SQS/TSQSGetQueueUrlRequest.html for options
                    var request  = new GetQueueUrlRequest(queueName);
                    var response = await _client.GetQueueUrlAsync(request);

                    if (response.HttpStatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception($"Could not check for existing queue '{queueName}' - got HTTP {response.HttpStatusCode}");
                    }

                    // See http://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SQS/TSQSSetQueueAttributesRequest.html for options
                    var setAttributesResponse = await _client.SetQueueAttributesAsync(response.QueueUrl, new Dictionary <string, string>
                    {
                        ["VisibilityTimeout"] = ((int)_peekLockDuration.TotalSeconds).ToString(CultureInfo.InvariantCulture)
                    });
                    if (setAttributesResponse.HttpStatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception($"Could not set attributes for queue '{queueName}' - got HTTP {setAttributesResponse.HttpStatusCode}");
                    }
                }
                catch (QueueDoesNotExistException)
                {
                    // See http://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/SQS/TSQSCreateQueueRequest.html for options
                    var createQueueRequest = new CreateQueueRequest(queueName)
                    {
                        Attributes =
                        {
                            ["VisibilityTimeout"] = ((int)_peekLockDuration.TotalSeconds).ToString(CultureInfo.InvariantCulture)
                        }
                    };

                    var response = await _client.CreateQueueAsync(createQueueRequest);

                    if (response.HttpStatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception($"Could not create queue '{queueName}' - got HTTP {response.HttpStatusCode}");
                    }
                }
            });
        }
コード例 #16
0
 public static string CreateBidQueue()
 {
     using (var sqs = new AmazonSQSClient())
     {
         var sqsRequest = new CreateQueueRequest {
             QueueName = auctionCode + "_Bid"
         };
         var createQueueResponse = sqs.CreateQueue(sqsRequest);
         return(createQueueResponse.QueueUrl);
     }
 }
コード例 #17
0
        static void Main(string[] args)
        {
            NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
            Console.WriteLine("*************************");
            Console.WriteLine("Amazon SQS");
            Console.WriteLine("************************\n");

            //var accessKey = JsonConfig.GetJsonValue("AccessKey");
            //var secretKey = JsonConfig.GetJsonValue("SecretKey");
            var accessKey = ConfigurationManager.AppSettings.Get("AccessKey");
            var secretKey = ConfigurationManager.AppSettings.Get("SecretKey");

            var queueName = "EmailQueue2";

            AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

            IAmazonSQS amazonSQS = new AmazonSQSClient(credentials, RegionEndpoint.EUWest2);

            Console.WriteLine("Create a queue called EmailQueue.\n");
            logger.Info("Create a queue called EmailQueue");
            logger.Info("Testing Logs");

            var sqsRequest = new CreateQueueRequest
            {
                QueueName = queueName
            };

            var createQueueResponse = amazonSQS.CreateQueueAsync(sqsRequest).Result;

            var myQueueRrl = createQueueResponse.QueueUrl;

            var listQueueRequest   = new ListQueuesRequest();
            var listQueuesResponce = amazonSQS.ListQueuesAsync(listQueueRequest);

            Console.WriteLine("List of Amazon SQS queuse.\n");

            foreach (var queueurl in listQueuesResponce.Result.QueueUrls)
            {
                Console.WriteLine($"QueueUrl : {queueurl}");
            }

            Console.WriteLine("Sendin a message to our emailQueue. \n");

            var sqsMessageRequest = new SendMessageRequest
            {
                QueueUrl    = myQueueRrl,
                MessageBody = "Email Information"
            };

            amazonSQS.SendMessageAsync(sqsMessageRequest);

            Console.WriteLine("Finished sending message to our sqs queue. \n");
            Console.ReadLine();
        }
コード例 #18
0
        private CreateQueueRequest CreateQueueRequest(DeveloperOptions devOptions)
        {
            var request = new CreateQueueRequest()
            {
                // TODO - need to determine where defaults are used, and then not create the constructor where value is null (to use default)
                QueueName  = devOptions.QueueName,
                Attributes = devOptions.Attributes,
            };

            return(request);
        }
コード例 #19
0
 public void Ensure()
 {
     if (!Exists())
     {
         var request = new CreateQueueRequest();
         request.QueueName = QueueName;
         var response = _sqsClient.CreateQueue(request);
         QueueUrl = response.QueueUrl;
         PopulateArn();
     }
 }
コード例 #20
0
        public void CreateQueue_WithName81CharsLong_ShouldThrowAmazonSQSException()
        {
            var sqsRequest = new CreateQueueRequest();

            sqsRequest.QueueName = new string('A', 81);

            var exception = Assert.Throws <AmazonSQSException>(() => _sqs.CreateQueue(sqsRequest));

            Assert.Contains("InvalidParameterValue", exception.ErrorCode);
            Assert.Equal(System.Net.HttpStatusCode.BadRequest, exception.StatusCode);
        }
コード例 #21
0
 public static string sendSqs(string data)
 {
   SendMessageRequest sendMessageRequest = new SendMessageRequest();
   CreateQueueRequest sqsRequest = new CreateQueueRequest();
   sqsRequest.QueueName = "mySqsQueue";
   CreateQueueResponse createQueueResponse = sqs.CreateQueue(sqsRequest);
   sendMessageRequest.QueueUrl = createQueueResponse.QueueUrl;
   sendMessageRequest.MessageBody = data;
   SendMessageResponse sendMessageresponse = SQS.SendMessage(sendMessageRequest);
   return sendMessageresponse.MessageId;
 }
コード例 #22
0
        public override IMessageQueue GetResponseQueue()
        {
            var createRequest = new CreateQueueRequest();

            createRequest.QueueName = Guid.NewGuid().ToString().Substring(0, 6);
            var createResponse = _sqsClient.CreateQueue(createRequest);

            var responseQueue = MessageQueueFactory.CreateInbound(createResponse.QueueUrl, MessagePattern.RequestResponse, true);

            return(responseQueue);
        }
コード例 #23
0
        protected override string CreateResponseQueueAddress()
        {
            var createQueueRequest = new CreateQueueRequest()
            {
                QueueName = Guid.NewGuid().ToString().Substring(0, 6)
            };

            var createQueueResponse = _sqsClient.CreateQueue(createQueueRequest);

            return(createQueueResponse.QueueUrl);
        }
コード例 #24
0
ファイル: SQSQueue.cs プロジェクト: cupcakecoders/GasMonitor
        public async Task <string> CreateSqsQueue()
        {
            CreateQueueRequest createQueueRequest = new CreateQueueRequest();

            createQueueRequest.QueueName = "KKLocationSQSQueue";

            var createQueueResponse = _sqsClient.CreateQueueAsync(createQueueRequest);
            var queueUrl            = createQueueResponse.Result.QueueUrl;

            return(queueUrl);
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: usulthemouse/codegallery
        static void Main(string[] args)
        {
            Console.Title = "CloudServiceBus: Client";

            AmazonSQS sqs             = AwsFacade.GetSqsClient();
            var       requestQueueUrl = ConfigurationManager.AppSettings["QueueUrl"];

            //create a queue for responses:
            var queueName          = Guid.NewGuid().ToString();
            var createQueueRequest = new CreateQueueRequest();

            createQueueRequest.QueueName = queueName;
            var createQueueResponse = sqs.CreateQueue(createQueueRequest);
            var responseQueueUrl    = createQueueResponse.CreateQueueResult.QueueUrl;

            var listener = new MessageListener();

            ThreadPool.QueueUserWorkItem(new WaitCallback(listener.StartListening), responseQueueUrl);

            Console.WriteLine("*");
            Console.WriteLine("Sending messages on URL: {0}", requestQueueUrl);
            Console.WriteLine("Receiving responses on URL: {0}", responseQueueUrl);
            Console.WriteLine("*");

            var messageBody = Console.ReadLine();

            while (messageBody != "x")
            {
                var parts = messageBody.Split(' ');
                if (parts[0] == "get")
                {
                    var duration       = int.Parse(parts[1]);
                    var serviceRequest = new GetChangedEmployeesRequest();
                    serviceRequest.LastChangeDate   = DateTime.Now.AddDays(duration).Date;
                    serviceRequest.ResponseQueueUrl = responseQueueUrl;
                    var request = new SendMessageRequest();
                    request.QueueUrl = requestQueueUrl;
                    request.RequestToBody(serviceRequest);
                    SendMessage(request, sqs, serviceRequest);
                }
                if (parts[0] == "flush")
                {
                    var serviceRequest = new FlushDataStoreRequest();
                    serviceRequest.StoreIdentifier = "Sixeyed-CloudServiceBus-ResponseData";
                    var request = new SendMessageRequest();
                    request.QueueUrl = requestQueueUrl;
                    request.RequestToBody(serviceRequest);
                    SendMessage(request, sqs, serviceRequest);
                }

                messageBody = Console.ReadLine();
            }
        }
コード例 #26
0
        public Task <CreateQueueResponse> CreateQueue(string QueueName, int Timeout)
        {
            var createQueueRequest = new CreateQueueRequest();

            createQueueRequest.QueueName = QueueName;
            var attrs = new Dictionary <string, string>();

            attrs.Add(QueueAttributeName.VisibilityTimeout, Timeout.ToString());
            createQueueRequest.Attributes = attrs;

            return(_client.CreateQueueAsync(createQueueRequest));
        }
コード例 #27
0
        public async Task <CreateQueueResponse> CreateQueue(string queueName)
        {
            var createQueueRequest = new CreateQueueRequest();

            createQueueRequest.QueueName = queueName;
            var attrs = new Dictionary <string, string>();

            attrs.Add(QueueAttributeName.VisibilityTimeout, "10");
            createQueueRequest.Attributes = attrs;

            return(await sqsClient.CreateQueueAsync(createQueueRequest));
        }
コード例 #28
0
 private static void EnsureQueue(IServiceHandler handler)
 {
     if (!_registeredHandlerUrls.ContainsKey(handler.QueueName))
     {
         var createQueueRequest = new CreateQueueRequest();
         createQueueRequest.QueueName = handler.QueueName;
         var createQueueResponse = SqsClient.CreateQueue(createQueueRequest);
         var queueUrl            = createQueueResponse.CreateQueueResult.QueueUrl;
         _registeredHandlerUrls[handler.QueueName] = queueUrl;
     }
     handler.QueueUrl = _registeredHandlerUrls[handler.QueueName];
 }
コード例 #29
0
        static async Task <string> CreateQueue(AmazonSQSClient client, string queueName)
        {
            var sqsRequest = new CreateQueueRequest
            {
                QueueName = queueName
            };
            var createQueueResponse = await client.CreateQueueAsync(sqsRequest).ConfigureAwait(false);

            var queueUrl = createQueueResponse.QueueUrl;

            return(queueUrl);
        }
コード例 #30
0
ファイル: Program.cs プロジェクト: wse/AWS
        static async void MainAsync(string[] args)
        {
            try
            {
                var listQueuesRequest  = new ListQueuesRequest();
                var listQueuesResponse = await _sqs.ListQueuesAsync(listQueuesRequest);

                try
                {
                    Console.WriteLine($"Checking for a queue called {_queueName}.\n");
                    var resp = await _sqs.GetQueueUrlAsync(_queueName);

                    _myQueueUrl = resp.QueueUrl;
                }
                catch (QueueDoesNotExistException quex)
                {
                    //Creating a queue
                    Console.WriteLine($"Create a queue called {_queueName}.\n");
                    var sqsRequest = new CreateQueueRequest {
                        QueueName = _queueName
                    };
                    var createQueueResponse = await _sqs.CreateQueueAsync(sqsRequest);

                    _myQueueUrl = createQueueResponse.QueueUrl;
                }

                //Sending a message
                for (int i = 0; i < 2; i++)
                {
                    var message = $"This is my message text-Id-{Guid.NewGuid().ToString("N")}";
                    //var message = $"This is my message text";
                    Console.WriteLine($"Sending a message to MyQueue : {message}");
                    var sendMessageRequest = new SendMessageRequest
                    {
                        QueueUrl    = _myQueueUrl, //URL from initial queue creation
                        MessageBody = message
                    };
                    await _sqs.SendMessageAsync(sendMessageRequest);
                }
            }
            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();
        }
コード例 #31
0
 public async Task CreateQueueAsync(string queueName, Dictionary<string, string> metadata = null)
 {
     var request = new CreateQueueRequest(_account, queueName, metadata);
     await request.ExecuteAsync(_optionalRetryPolicy);
 }
コード例 #32
0
        public void CreateQueue(string queueName, Dictionary<string, string> metadata = null)
		{
			var request = new CreateQueueRequest(_account, queueName, metadata);
            request.Execute(_optionalRetryPolicy);
		}