/// <summary> /// /// Sets an attribute of a queue. Currently, you can set only the VisibilityTimeout attribute for a queue. /// /// </summary> /// <param name="service">Instance of AmazonSQS service</param> /// <param name="request">SetQueueAttributesRequest request</param> public static void InvokeSetQueueAttributes(AmazonSQS service, SetQueueAttributesRequest request) { try { SetQueueAttributesResponse response = service.SetQueueAttributes(request); Console.WriteLine ("Service Response"); Console.WriteLine ("============================================================================="); Console.WriteLine (); Console.WriteLine(" SetQueueAttributesResponse"); if (response.IsSetResponseMetadata()) { Console.WriteLine(" ResponseMetadata"); ResponseMetadata responseMetadata = response.ResponseMetadata; if (responseMetadata.IsSetRequestId()) { Console.WriteLine(" RequestId"); Console.WriteLine(" {0}", responseMetadata.RequestId); } } } 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("XML: " + ex.XML); } }
private void SetPermissions() { var setQueueAttributeRequest = new SetQueueAttributesRequest() .WithQueueUrl(_config.SqsQueueUrl) .WithAttribute(new Attribute { Name = "Policy", Value = AllowSnsAttribute() }); _client.SetQueueAttributes(setQueueAttributeRequest); }
public void set_permissions() { var setQueueAttributeRequest = new SetQueueAttributesRequest() .WithQueueUrl(_queueUrl) .WithAttribute(new Attribute { Name = "Policy", Value = AllowSnsAttribute() }); var result = _client.SetQueueAttributes(setQueueAttributeRequest); Console.WriteLine(result.ToXML()); var getQueueAttributesResponse = _client.GetQueueAttributes( new GetQueueAttributesRequest().WithAttributeName("Policy").WithQueueUrl(_queueUrl)); foreach (var attribute in getQueueAttributesResponse.GetQueueAttributesResult.Attribute) { Console.WriteLine("{0} : {1}",attribute.Name,attribute.Value); } }
public static void Save(string sourceArn, string queueArn, string queueUrl, IAmazonSQS client) { var topicArnWildcard = CreateTopicArnWildcard(sourceArn); ActionIdentifier[] actions = { SQSActionIdentifiers.SendMessage }; Policy sqsPolicy = new Policy() .WithStatements(new Statement(Statement.StatementEffect.Allow) .WithPrincipals(Principal.AllUsers) .WithResources(new Resource(queueArn)) .WithConditions(ConditionFactory.NewSourceArnCondition(topicArnWildcard)) .WithActionIdentifiers(actions)); SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest(); setQueueAttributesRequest.QueueUrl = queueUrl; setQueueAttributesRequest.Attributes["Policy"] = sqsPolicy.ToJson(); client.SetQueueAttributes(setQueueAttributesRequest); }
protected override bool Execute(AmazonSQS client) { Log.LogMessage(MessageImportance.Normal, "Granting SendMessage rights to SQS Queue at {0}", QueueUrl); string queueArn = GetQueueArn(client, QueueUrl); Log.LogMessage(MessageImportance.Low, "Queue {0} Arn: {1}", QueueUrl, queueArn); var request = new SetQueueAttributesRequest { QueueUrl = QueueUrl }; var attribute = new Attribute { Name = "Policy", Value = ConstructPolicy(queueArn, SourceArn) }; request.Attribute = new List<Attribute> { attribute }; client.SetQueueAttributes(request); Logger.LogMessage(MessageImportance.Normal, "Granted rights for source {0} to SendMessage to SQS at {1}", SourceArn, QueueUrl); return true; }
public void UpdateRedrivePolicy(RedrivePolicy requestedRedrivePolicy) { if (RedrivePolicyNeedsUpdating(requestedRedrivePolicy)) { var request = new SetQueueAttributesRequest { QueueUrl = Url, Attributes = new Dictionary<string, string> { {JustSayingConstants.ATTRIBUTE_REDRIVE_POLICY, requestedRedrivePolicy.ToString()} } }; var response = Client.SetQueueAttributes(request); if (response.HttpStatusCode == HttpStatusCode.OK) { RedrivePolicy = requestedRedrivePolicy; } } }
public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.SQS.Model.SetQueueAttributesRequest(); if (cmdletContext.Attribute != null) { request.Attributes = cmdletContext.Attribute; } if (cmdletContext.QueueUrl != null) { request.QueueUrl = cmdletContext.QueueUrl; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return(output); }
public ISubscribeReponseMessage Subscribe(string queueUrl) { var sqsConfig = new AmazonSQSConfig {ServiceURL = SqsServiceUrl}; var snsConfig = new AmazonSimpleNotificationServiceConfig {ServiceURL = SnsServiceUrl}; using (var sqsClient = _awsConfig.CreateAwsClient<AmazonSQSClient>(sqsConfig)) { var attributesRequest = new GetQueueAttributesRequest(queueUrl, new List<string> {"QueueArn"}); var attributesResponse = sqsClient.GetQueueAttributes(attributesRequest); using (var snsClient = _awsConfig.CreateAwsClient<AmazonSimpleNotificationServiceClient>(snsConfig)) { var subribeResonse = snsClient.Subscribe(new SubscribeRequest(TopicArn, "sqs", attributesResponse.QueueARN)); } var actions = new ActionIdentifier[2]; actions[0] = SQSActionIdentifiers.SendMessage; actions[1] = SQSActionIdentifiers.ReceiveMessage; var sqsPolicy = new Policy().WithStatements( new Statement(Statement.StatementEffect.Allow).WithPrincipals(Principal.AllUsers) .WithResources( new Resource(attributesResponse.QueueARN)) .WithConditions( ConditionFactory.NewSourceArnCondition( TopicArn)) .WithActionIdentifiers(actions)); var setQueueAttributesRequest = new SetQueueAttributesRequest(); var attributes = new Dictionary<string, string> {{"Policy", sqsPolicy.ToJson()}}; var attRequest = new SetQueueAttributesRequest(attributesRequest.QueueUrl, attributes); sqsClient.SetQueueAttributes(attRequest); return new SubcriptionMessage("Ok"); } }
public void create_sqs_queue() { GetUserNameAndPassword(); var sqsClient = Amazon.AWSClientFactory.CreateAmazonSQSClient(_key, _secret); var snsTopic = Amazon.AWSClientFactory.CreateAmazonSNSClient(_key, _secret); var topicArn = "arn:aws:sns:us-east-1:451419498740:Elliott-has-an-awesome-blog"; //Create a new SQS queue var createQueueRequest = new CreateQueueRequest().WithQueueName("elliotts-blog"); var createQueueResponse = sqsClient.CreateQueue(createQueueRequest); // keep the queueUrl handy var queueUrl = createQueueResponse.CreateQueueResult.QueueUrl; // get the Access Resource Name so we can allow the SNS to put messages on it var getQueueArnRequest = new GetQueueAttributesRequest() .WithQueueUrl(queueUrl) .WithAttributeName("QueueArn"); var getQueueArnResponse = sqsClient.GetQueueAttributes(getQueueArnRequest); var queueArn = getQueueArnResponse.GetQueueAttributesResult.Attribute[0].Value; //create a Policy for the SQS queue that allows SNS to publish to it var allowSnsStatement = new Statement(Statement.StatementEffect.Allow) .WithPrincipals(Principal.AllUsers) .WithResources(new Resource(queueArn)) .WithConditions(ConditionFactory.NewSourceArnCondition(topicArn)) .WithActionIdentifiers(SQSActionIdentifiers.SendMessage); var policy = new Policy("allow sns").WithStatements(new[] {allowSnsStatement}); var attribute = new Attribute().WithName("Policy").WithValue(policy.ToJson()); var setQueueAttributesRequest = new SetQueueAttributesRequest().WithQueueUrl(queueUrl).WithAttribute(attribute); sqsClient.SetQueueAttributes(setQueueAttributesRequest); // ok, now lets create the subscription for sqs with the queueArn we created var subscribeRequest = new SubscribeRequest() .WithEndpoint(queueArn) .WithTopicArn(topicArn) .WithProtocol("sqs"); snsTopic.Subscribe(subscribeRequest); }
protected internal override void UpdateQueueAttribute(SqsBasicConfiguration queueConfig) { if (QueueNeedsUpdating(queueConfig)) { var request = new SetQueueAttributesRequest { QueueUrl = Url, Attributes = new Dictionary<string, string> { { JustSayingConstants.ATTRIBUTE_RETENTION_PERIOD, queueConfig.ErrorQueueRetentionPeriodSeconds.ToString() } } }; var response = Client.SetQueueAttributes(request); if (response.HttpStatusCode == HttpStatusCode.OK) { MessageRetentionPeriod = queueConfig.ErrorQueueRetentionPeriodSeconds; } } }
public static bool Add_Q_Premissions_Everybody(String Q_url) { String sid = "\"Sid\":\"" + Q_url + "\""; String effect = "\"Effect\":\"Allow\""; String pricipal = "\"Principal\":{\"AWS\":\"*\"}"; String action = "\"Action\":\"SQS:*\""; String Q_arn; if (!Get_Q_arn(Q_url, out Q_arn)) return false; String resource = "\"Resource\":\"" + Q_arn + "\""; String myPolicy = "{\"Version\":\"2008-10-17\",\"Id\":\"" + Q_arn + "/SQSDefaultPolicy\",\"Statement\":[{" + sid + "," + effect + "," + pricipal + "," + action + "," + resource + "}]}"; SetQueueAttributesRequest sqa_request = new SetQueueAttributesRequest(); sqa_request.Attribute = new List<Amazon.SQS.Model.Attribute>(); Amazon.SQS.Model.Attribute att = new Amazon.SQS.Model.Attribute(); att.Name = "Policy"; att.Value = myPolicy; sqa_request.Attribute.Add(att); sqa_request.QueueUrl = Q_url; SetQueueAttributesResponse sqa_response = sqs_client.SetQueueAttributes(sqa_request); return true; }
/// <summary> /// CreateQueueTopicPolicy: Create Request Queue that subscribes to Topic, /// add permission/policy so topic can publish to the Queue /// </summary> /// <param name="queueName"></param> /// <returns></returns> private string CreateQueueTopicPolicy(string queueName) { Debug.WriteLine("Queuename: " + queueName); var msg1 = new Amazon.SQS.Model.CreateQueueRequest() .WithQueueName(queueName) .WithDefaultVisibilityTimeout(60) .WithDelaySeconds(20); Amazon.SQS.Model.CreateQueueResponse rsp = queue.CreateQueue(msg1); if (rsp.CreateQueueResult.IsSetQueueUrl()) { var attr = queue.GetQueueAttributes(new Amazon.SQS.Model.GetQueueAttributesRequest() .WithQueueUrl(rsp.CreateQueueResult.QueueUrl) .WithAttributeName(new string[] { "QueueArn" })); if (attr.IsSetGetQueueAttributesResult() && attr.GetQueueAttributesResult.IsSetAttribute()) { var policy = new Policy("QueuePolicy" + queueName); policy.WithStatements(new Statement(Statement.StatementEffect.Allow) .WithPrincipals(new Principal("*")) .WithActionIdentifiers(Amazon.Auth.AccessControlPolicy.ActionIdentifiers.SQSActionIdentifiers.SendMessage) .WithResources(new Resource(attr.GetQueueAttributesResult.QueueARN)) .WithConditions(Amazon.Auth.AccessControlPolicy.ConditionFactory.NewSourceArnCondition(topicArn))); var setAttrsRequest = new Amazon.SQS.Model.SetQueueAttributesRequest() .WithQueueUrl(rsp.CreateQueueResult.QueueUrl); setAttrsRequest.Attribute.Add(new Amazon.SQS.Model.Attribute() .WithName("Policy") .WithValue(policy.ToJson())); var setAttrsResponse = queue.SetQueueAttributes(setAttrsRequest); } return(rsp.CreateQueueResult.QueueUrl); } return(null); }
private Amazon.SQS.Model.SetQueueAttributesResponse CallAWSServiceOperation(IAmazonSQS client, Amazon.SQS.Model.SetQueueAttributesRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Queue Service (SQS)", "SetQueueAttributes"); try { #if DESKTOP return(client.SetQueueAttributes(request)); #elif CORECLR return(client.SetQueueAttributesAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
/// <summary> /// Initiates the asynchronous execution of the SetQueueAttributes operation. /// <seealso cref="Amazon.SQS.IAmazonSQS.SetQueueAttributes"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the SetQueueAttributes operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public async Task<SetQueueAttributesResponse> SetQueueAttributesAsync(SetQueueAttributesRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SetQueueAttributesRequestMarshaller(); var unmarshaller = SetQueueAttributesResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, SetQueueAttributesRequest, SetQueueAttributesResponse>(request, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// Sets the value of one or more queue attributes. When you change a queue's attributes, /// the change can take up to 60 seconds for most of the attributes to propagate /// throughout the SQS system. Changes made to the <code>MessageRetentionPeriod</code> /// attribute can take up to 15 minutes. /// /// <note>Going forward, new attributes might be added. If you are writing code /// that calls this action, we recommend that you structure your code so that it can handle /// new attributes gracefully.</note> /// </summary> /// <param name="request">Container for the necessary parameters to execute the SetQueueAttributes service method.</param> /// /// <returns>The response from the SetQueueAttributes service method, as returned by SQS.</returns> /// <exception cref="InvalidAttributeNameException"> /// The attribute referred to does not exist. /// </exception> public SetQueueAttributesResponse SetQueueAttributes(SetQueueAttributesRequest request) { var marshaller = new SetQueueAttributesRequestMarshaller(); var unmarshaller = SetQueueAttributesResponseUnmarshaller.Instance; return Invoke<SetQueueAttributesRequest,SetQueueAttributesResponse>(request, marshaller, unmarshaller); }
/// <summary> /// Initiates the asynchronous execution of the SetQueueAttributes operation. /// <seealso cref="Amazon.SQS.IAmazonSQS"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the SetQueueAttributes operation on AmazonSQSClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndSetQueueAttributes /// operation.</returns> public IAsyncResult BeginSetQueueAttributes(SetQueueAttributesRequest request, AsyncCallback callback, object state) { var marshaller = new SetQueueAttributesRequestMarshaller(); var unmarshaller = SetQueueAttributesResponseUnmarshaller.Instance; return BeginInvoke<SetQueueAttributesRequest>(request, marshaller, unmarshaller, callback, state); }
/// <summary> /// Initiates the asynchronous execution of the SetQueueAttributes operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the SetQueueAttributes operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<SetQueueAttributesResponse> SetQueueAttributesAsync(SetQueueAttributesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SetQueueAttributesRequestMarshaller(); var unmarshaller = SetQueueAttributesResponseUnmarshaller.Instance; return InvokeAsync<SetQueueAttributesRequest,SetQueueAttributesResponse>(request, marshaller, unmarshaller, cancellationToken); }
/// <summary> /// Sets the value of one or more queue attributes. When you change a queue's attributes, /// the change can take up to 60 seconds for most of the attributes to propagate /// throughout the SQS system. Changes made to the <code>MessageRetentionPeriod</code> /// attribute can take up to 15 minutes. /// /// <note>Going forward, new attributes might be added. If you are writing code /// that calls this action, we recommend that you structure your code so that it can handle /// new attributes gracefully.</note> /// </summary> /// <param name="queueUrl">The URL of the Amazon SQS queue to take action on.</param> /// <param name="attributes">A map of attributes to set. The following lists the names, descriptions, and values of the special request parameters the <code>SetQueueAttributes</code> action uses: <ul> <li><code>DelaySeconds</code> - The time in seconds that the delivery of all messages in the queue will be delayed. An integer from 0 to 900 (15 minutes). The default for this attribute is 0 (zero).</li> <li><code>MaximumMessageSize</code> - The limit of how many bytes a message can contain before Amazon SQS rejects it. An integer from 1024 bytes (1 KiB) up to 262144 bytes (256 KiB). The default for this attribute is 262144 (256 KiB).</li> <li><code>MessageRetentionPeriod</code> - The number of seconds Amazon SQS retains a message. Integer representing seconds, from 60 (1 minute) to 1209600 (14 days). The default for this attribute is 345600 (4 days).</li> <li><code>Policy</code> - The queue's policy. A valid form-url-encoded policy. For more information about policy structure, see <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/BasicStructure.html">Basic Policy Structure</a> in the <i>Amazon SQS Developer Guide</i>. For more information about form-url-encoding, see <a href="http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1">http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1</a>.</li> <li><code>ReceiveMessageWaitTimeSeconds</code> - The time for which a ReceiveMessage call will wait for a message to arrive. An integer from 0 to 20 (seconds). The default for this attribute is 0. </li> <li><code>VisibilityTimeout</code> - The visibility timeout for the queue. An integer from 0 to 43200 (12 hours). The default for this attribute is 30. For more information about visibility timeout, see Visibility Timeout in the <i>Amazon SQS Developer Guide</i>.</li> <li><code>RedrivePolicy</code> - The parameters for dead letter queue functionality of the source queue. For more information about RedrivePolicy and dead letter queues, see Using Amazon SQS Dead Letter Queues in the <i>Amazon SQS Developer Guide</i>.</li> </ul> </param> /// /// <returns>The response from the SetQueueAttributes service method, as returned by SQS.</returns> /// <exception cref="InvalidAttributeNameException"> /// The attribute referred to does not exist. /// </exception> public SetQueueAttributesResponse SetQueueAttributes(string queueUrl, Dictionary<string, string> attributes) { var request = new SetQueueAttributesRequest(); request.QueueUrl = queueUrl; request.Attributes = attributes; return SetQueueAttributes(request); }
public virtual void GrantNotificationPermission(AmazonSQSClient sqsClient, string queueArn, string queueUrl, string topicArn) { // Create a policy to allow the queue to receive notifications from the SNS topic var policy = new Policy("SubscriptionPermission") { Statements = { new Statement(Statement.StatementEffect.Allow) { Actions = {SQSActionIdentifiers.SendMessage}, Principals = {new Principal("*")}, Conditions = {ConditionFactory.NewSourceArnCondition(topicArn)}, Resources = {new Resource(queueArn)} } } }; var attributes = new Dictionary<string, string>(); attributes.Add("Policy", policy.ToJson()); // Create the request to set the queue attributes for policy var setQueueAttributesRequest = new SetQueueAttributesRequest { QueueUrl = queueUrl, Attributes = attributes }; // Set the queue policy sqsClient.SetQueueAttributes(setQueueAttributesRequest); }
private void setMaximumMessageSize(String queueUrl) { Amazon.SQS.Model.Attribute[] attrs = new Amazon.SQS.Model.Attribute[1]; attrs[0] = new Amazon.SQS.Model.Attribute().WithName("MaximumMessageSize").WithValue("65536"); SetQueueAttributesRequest request = new SetQueueAttributesRequest().WithQueueUrl(queueUrl).WithAttribute(attrs); sqs.SetQueueAttributes(request); }
internal SetQueueAttributesResponse SetQueueAttributes(SetQueueAttributesRequest request) { var task = SetQueueAttributesAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
protected internal virtual void UpdateQueueAttribute(SqsBasicConfiguration queueConfig) { if (QueueNeedsUpdating(queueConfig)) { var request = new SetQueueAttributesRequest { QueueUrl = Url, Attributes = new Dictionary<string, string> { {JustSayingConstants.ATTRIBUTE_RETENTION_PERIOD, queueConfig.MessageRetentionSeconds.ToString()}, { JustSayingConstants.ATTRIBUTE_VISIBILITY_TIMEOUT, queueConfig.VisibilityTimeoutSeconds.ToString() }, {JustSayingConstants.ATTRIBUTE_DELIVERY_DELAY, queueConfig.DeliveryDelaySeconds.ToString()} } }; var response = Client.SetQueueAttributes(request); if (response.HttpStatusCode == HttpStatusCode.OK) { MessageRetentionPeriod = queueConfig.MessageRetentionSeconds; VisibilityTimeout = queueConfig.VisibilityTimeoutSeconds; DeliveryDelay = queueConfig.DeliveryDelaySeconds; } } }
internal void setupTopicAndQueue() { long ticks = DateTime.Now.Ticks; this.topicArn = this.snsClient.CreateTopic(new CreateTopicRequest() { Name = "GlacierDownload-" + ticks }).TopicArn; this.queueUrl = this.sqsClient.CreateQueue(new CreateQueueRequest() { QueueName = "GlacierDownload-" + ticks }).QueueUrl; this.queueArn = this.sqsClient.GetQueueAttributes(new GetQueueAttributesRequest() { QueueUrl = this.queueUrl, AttributeNames = new List<string> { SQSConstants.ATTRIBUTE_QUEUE_ARN } }).Attributes[SQSConstants.ATTRIBUTE_QUEUE_ARN]; this.snsClient.Subscribe(new SubscribeRequest() { Endpoint = this.queueArn, Protocol = "sqs", TopicArn = this.topicArn }); var policy = SQS_POLICY.Replace("{QuereArn}", this.queueArn).Replace("{TopicArn}", this.topicArn); var setQueueAttributesRequest = new SetQueueAttributesRequest() { QueueUrl = this.queueUrl }; setQueueAttributesRequest.Attributes.Add("Policy", policy); this.sqsClient.SetQueueAttributes(setQueueAttributesRequest); }
public void Test_SetQueueAttributes_With_Valid_Attribute_And_Check_For_Valid_Response() { bool hasCallbackArrived = false; bool actualValue = false; bool expectedValue = true; SQSResponseEventHandler<object, ResponseEventArgs> handler = null; handler = delegate(object sender, ResponseEventArgs args) { ISQSResponse result = args.Response; //Unhook from event. _client.OnSQSResponse -= handler; SetQueueAttributesResponse response = result as SetQueueAttributesResponse; if (null != response) actualValue = true; hasCallbackArrived = true; }; //Hook to event _client.OnSQSResponse += handler; //Create request object. SetQueueAttributesRequest request = new SetQueueAttributesRequest(); request.QueueUrl = string.Format("{0}/{1}", QueueURL, _queue_UnitTesting); request.Attribute.Add(new Amazon.SQS.Model.Attribute { Name = "MaximumMessageSize", Value = "5000" }); _client.SetQueueAttributes(request); EnqueueConditional(() => hasCallbackArrived); EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue)); EnqueueTestComplete(); }
public void Test_SetQueueAttributes_With_Multiple_Attributes_With_One_InvalidAttribute_And_Check_For_Error_Response() { bool hasCallbackArrived = false; string actualValue = string.Empty; string expectedValue = "InvalidAttributeName"; SQSResponseEventHandler<object, ResponseEventArgs> handler = null; handler = delegate(object sender, ResponseEventArgs args) { ISQSResponse result = args.Response; //Unhook from event. _client.OnSQSResponse -= handler; AmazonSQSException exception = result as AmazonSQSException; if (null != exception) actualValue = exception.ErrorCode; hasCallbackArrived = true; }; //Hook to event _client.OnSQSResponse += handler; //Create request object. SetQueueAttributesRequest request = new SetQueueAttributesRequest(); request.QueueUrl = string.Format("{0}/{1}", QueueURL, _queue_UnitTesting); request.Attribute.Add(new Amazon.SQS.Model.Attribute { Name = "VisibilityTimeout", Value = "3" }); request.Attribute.Add(new Amazon.SQS.Model.Attribute { Name = "invalidAttribute", Value = "6000" }); _client.SetQueueAttributes(request); EnqueueConditional(() => hasCallbackArrived); EnqueueCallback(() => Assert.IsTrue(string.Compare(expectedValue, actualValue) == 0)); EnqueueTestComplete(); }
/// <summary> /// Sets the value of one or more queue attributes. When you change a queue's attributes, /// the change can take up to 60 seconds for most of the attributes to propagate throughout /// the Amazon SQS system. Changes made to the <code>MessageRetentionPeriod</code> attribute /// can take up to 15 minutes. /// /// <note> /// <para> /// In the future, new attributes might be added. If you write code that calls this action, /// we recommend that you structure your code so that it can handle new attributes gracefully. /// </para> /// </note> /// </summary> /// <param name="queueUrl">The URL of the Amazon SQS queue whose attributes are set. Queue URLs are case-sensitive.</param> /// <param name="attributes">A map of attributes to set. The following lists the names, descriptions, and values of the special request parameters that the <code>SetQueueAttributes</code> action uses: <ul> <li> <code>DelaySeconds</code> - The number of seconds for which the delivery of all messages in the queue is delayed. Valid values: An integer from 0 to 900 (15 minutes). The default is 0 (zero). </li> <li> <code>MaximumMessageSize</code> - The limit of how many bytes a message can contain before Amazon SQS rejects it. Valid values: An integer from 1,024 bytes (1 KiB) up to 262,144 bytes (256 KiB). The default is 262,144 (256 KiB). </li> <li> <code>MessageRetentionPeriod</code> - The number of seconds for which Amazon SQS retains a message. Valid values: An integer representing seconds, from 60 (1 minute) to 1,209,600 (14 days). The default is 345,600 (4 days). </li> <li> <code>Policy</code> - The queue's policy. A valid AWS policy. For more information about policy structure, see <a href="http://docs.aws.amazon.com/IAM/latest/UserGuide/PoliciesOverview.html">Overview of AWS IAM Policies</a> in the <i>Amazon IAM User Guide</i>. </li> <li> <code>ReceiveMessageWaitTimeSeconds</code> - The number of seconds for which a <code> <a>ReceiveMessage</a> </code> action waits for a message to arrive. Valid values: an integer from 0 to 20 (seconds). The default is 0. </li> <li> <code>RedrivePolicy</code> - The parameters for the dead letter queue functionality of the source queue. For more information about the redrive policy and dead letter queues, see <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html">Using Amazon SQS Dead Letter Queues</a> in the <i>Amazon SQS Developer Guide</i>. <note> The dead letter queue of a FIFO queue must also be a FIFO queue. Similarly, the dead letter queue of a standard queue must also be a standard queue. </note> </li> <li> <code>VisibilityTimeout</code> - The visibility timeout for the queue. Valid values: an integer from 0 to 43,200 (12 hours). The default is 30. For more information about the visibility timeout, see <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html">Visibility Timeout</a> in the <i>Amazon SQS Developer Guide</i>. </li> </ul> The following attribute applies only to <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html">FIFO (first-in-first-out) queues</a>: <ul> <li> <code>ContentBasedDeduplication</code> - Enables content-based deduplication. For more information, see <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queues.html#FIFO-queues-exactly-once-processing">Exactly-Once Processing</a> in the <i>Amazon SQS Developer Guide</i>. <ul> <li> Every message must have a unique <code>MessageDeduplicationId</code>, <ul> <li> You may provide a <code>MessageDeduplicationId</code> explicitly. </li> <li> If you aren't able to provide a <code>MessageDeduplicationId</code> and you enable <code>ContentBasedDeduplication</code> for your queue, Amazon SQS uses a SHA-256 hash to generate the <code>MessageDeduplicationId</code> using the body of the message (but not the attributes of the message). </li> <li> If you don't provide a <code>MessageDeduplicationId</code> and the queue doesn't have <code>ContentBasedDeduplication</code> set, the action fails with an error. </li> <li> If the queue has <code>ContentBasedDeduplication</code> set, your <code>MessageDeduplicationId</code> overrides the generated one. </li> </ul> </li> <li> When <code>ContentBasedDeduplication</code> is in effect, messages with identical content sent within the deduplication interval are treated as duplicates and only one copy of the message is delivered. </li> <li> You can also use <code>ContentBasedDeduplication</code> for messages with identical content to be treated as duplicates. </li> <li> If you send one message with <code>ContentBasedDeduplication</code> enabled and then another message with a <code>MessageDeduplicationId</code> that is the same as the one generated for the first <code>MessageDeduplicationId</code>, the two messages are treated as duplicates and only one copy of the message is delivered. </li> </ul> </li> </ul> Any other valid special request parameters (such as the following) are ignored: <ul> <li> <code>ApproximateNumberOfMessages</code> </li> <li> <code>ApproximateNumberOfMessagesDelayed</code> </li> <li> <code>ApproximateNumberOfMessagesNotVisible</code> </li> <li> <code>CreatedTimestamp</code> </li> <li> <code>LastModifiedTimestamp</code> </li> <li> <code>QueueArn</code> </li> </ul></param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// /// <returns>The response from the SetQueueAttributes service method, as returned by SQS.</returns> /// <exception cref="Amazon.SQS.Model.InvalidAttributeNameException"> /// The attribute referred to doesn't exist. /// </exception> public Task<SetQueueAttributesResponse> SetQueueAttributesAsync(string queueUrl, Dictionary<string, string> attributes, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var request = new SetQueueAttributesRequest(); request.QueueUrl = queueUrl; request.Attributes = attributes; return SetQueueAttributesAsync(request, cancellationToken); }
public string SetSqsPolicyForSnsPublish(Uri queueUrl, string queueArn, string mytopicArn) { Validate.That(queueUrl).IsNotNull(); Validate.That(queueArn).IsNotNullOrEmpty(); Validate.That(mytopicArn).IsNotNullOrEmpty(); var sqsPolicy = new Policy().WithStatements( new Statement(Statement.StatementEffect.Allow) .WithResources(new Resource(queueArn)) .WithPrincipals(Principal.AllUsers) .WithActionIdentifiers(SQSActionIdentifiers.SendMessage) .WithConditions(ConditionFactory.NewCondition(ConditionFactory.ArnComparisonType.ArnEquals, conditionSourceArn, mytopicArn))); var setQueueAttributesRequest = new SetQueueAttributesRequest().WithQueueUrl(queueUrl.AbsoluteUri).WithPolicy(sqsPolicy.ToJson()); using (var sqs = amazonSqsFactory()) { var response = sqs.SetQueueAttributes(setQueueAttributesRequest); return response.ResponseMetadata.RequestId; } }
/// <summary> /// <para>Sets the value of one or more queue attributes.</para> <para><b>NOTE:</b>Going forward, new attributes might be added. If you are /// writing code that calls this action, we recommend that you structure your code so that it can handle new attributes gracefully.</para> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the SetQueueAttributes service method on /// AmazonSQS.</param> /// /// <exception cref="T:Amazon.SQS.Model.InvalidAttributeNameException" /> public SetQueueAttributesResponse SetQueueAttributes(SetQueueAttributesRequest request) { var task = SetQueueAttributesAsync(request); try { return task.Result; } catch(AggregateException e) { ExceptionDispatchInfo.Capture(e.InnerException).Throw(); return null; } }
/// <summary> /// <para>Sets the value of one or more queue attributes. Valid attributes that can be set are [VisibilityTimeout, Policy, MaximumMessageSize, /// MessageRetentionPeriod, ReceiveMessageWaitTimeSeconds].</para> /// </summary> /// /// <param name="setQueueAttributesRequest">Container for the necessary parameters to execute the SetQueueAttributes service method on /// AmazonSQS.</param> /// /// <exception cref="InvalidAttributeNameException"/> public SetQueueAttributesResponse SetQueueAttributes(SetQueueAttributesRequest setQueueAttributesRequest) { IAsyncResult asyncResult = invokeSetQueueAttributes(setQueueAttributesRequest, null, null, true); return EndSetQueueAttributes(asyncResult); }
private SqsQueueDefinition UpdateQueue(SqsQueueName sqsQueueName, SetQueueAttributesRequest request, bool? disasbleBuffering = null) { if (string.IsNullOrEmpty(request.QueueUrl)) { request.QueueUrl = GetQueueUrl(sqsQueueName); } var response = SqsClient.SetQueueAttributes(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.). var queueDefinition = GetQueueDefinition(sqsQueueName, request.QueueUrl); queueDefinition.DisableBuffering = disasbleBuffering ?? DisableBuffering; queueNameMap[queueDefinition.QueueName] = queueDefinition; return queueDefinition; }
/// <summary> /// Initiates the asynchronous execution of the SetQueueAttributes operation. /// <seealso cref="Amazon.SQS.IAmazonSQS.SetQueueAttributes"/> /// </summary> /// /// <param name="setQueueAttributesRequest">Container for the necessary parameters to execute the SetQueueAttributes operation on /// AmazonSQS.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> public IAsyncResult BeginSetQueueAttributes(SetQueueAttributesRequest setQueueAttributesRequest, AsyncCallback callback, object state) { return invokeSetQueueAttributes(setQueueAttributesRequest, callback, state, false); }
/// <summary> /// <para>Sets the value of one or more queue attributes. Valid attributes that can be set are [VisibilityTimeout, Policy, MaximumMessageSize, /// MessageRetentionPeriod, ReceiveMessageWaitTimeSeconds].</para> /// </summary> /// /// <param name="setQueueAttributesRequest">Container for the necessary parameters to execute the SetQueueAttributes service method on /// AmazonSQS.</param> /// /// <exception cref="T:Amazon.SQS.Model.InvalidAttributeNameException" /> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public Task<SetQueueAttributesResponse> SetQueueAttributesAsync(SetQueueAttributesRequest setQueueAttributesRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SetQueueAttributesRequestMarshaller(); var unmarshaller = SetQueueAttributesResponseUnmarshaller.GetInstance(); return Invoke<IRequest, SetQueueAttributesRequest, SetQueueAttributesResponse>(setQueueAttributesRequest, marshaller, unmarshaller, signer, cancellationToken); }
IAsyncResult invokeSetQueueAttributes(SetQueueAttributesRequest setQueueAttributesRequest, AsyncCallback callback, object state, bool synchronized) { IRequest irequest = new SetQueueAttributesRequestMarshaller().Marshall(setQueueAttributesRequest); var unmarshaller = SetQueueAttributesResponseUnmarshaller.GetInstance(); AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller); Invoke(result); return result; }