Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redrive Policy Example #124

Open
harry9111985 opened this issue Jan 4, 2018 · 7 comments
Open

Redrive Policy Example #124

harry9111985 opened this issue Jan 4, 2018 · 7 comments

Comments

@harry9111985
Copy link

harry9111985 commented Jan 4, 2018

Hi @adamw ,

If you have any samples to create redrivepolicy links using dead queues that would be great . Currently , I am trying to create a redrivepolicy during CreateQueueRequest (Amazon Java SDK) using queue attributes. I do get a debug point on the RedrivePolicy.class in the elasticmq package . But elasticmq doesnt seem to create a link with the DeadLetterQueue.

My java code :

final Map<String, String> deadLetterQueueAttrs = new HashMap<>();
deadLetterQueueAttrs.put("VisibilityTimeout", "600");
final CreateQueueRequest createDeadLetterQueueRequest = new CreateQueueRequest()
.withQueueName(queueName + "-error")
.withAttributes(deadLetterQueueAttrs);

	final CreateQueueResult deadLetterQueueResult = amazonSQSAsyncClient.createQueue(createDeadLetterQueueRequest);
	final GetQueueAttributesResult deadLetterQueueArnResult = amazonSQSAsyncClient.getQueueAttributes(deadLetterQueueResult.getQueueUrl(), Arrays.asList("QueueArn"));

	final Map<String, String> queueAttributes = new HashMap<>();
	final StringBuilder redrivePolicyParamBuilder = new StringBuilder()
		.append("{\"deadLetterTargetArn\" : \"")
		.append(deadLetterQueueArnResult.getAttributes().get("QueueArn"))
		.append("\",")
		.append("\"maxReceiveCount\": \"1\"}");
	queueAttributes.put("RedrivePolicy", redrivePolicyParamBuilder.toString());
	queueAttributes.put("VisibilityTimeout","600");

	final CreateQueueRequest createQueueRequest = new CreateQueueRequest()
		.withQueueName(queueName)
		.withAttributes(queueAttributes);

	final CreateQueueResult createQueueResult = amazonSQSAsyncClient.createQueue(createQueueRequest);

No errors are thrown but the redrive policy link is not created,

Kindly help.

Regards,
Harish

@adamw
Copy link
Member

adamw commented Jan 4, 2018 via email

@harry9111985
Copy link
Author

harry9111985 commented Jan 4, 2018

Hi @adamw ,

Thanks for your response. I am not sure that piece of code works in Java . I am doing the same thing in Java as mentioned in the above snippet .

I get the following CreateRequest in the logs

Creating queue QueueData(test-api-log,MillisVisibilityTimeout(600000),PT0S,PT0S,2018-01-04T20:31:29.425+10:00,2018-01-04T20:31:29.425+10:00,Some(DeadLettersQueueData(test-api-log-error,1)),None)

But when I get "All" Attributes for the queue I get the following

Queue Attributes : {"attributes":{"ReceiveMessageWaitTimeSeconds":"0","ApproximateNumberOfMessagesDelayed":"0","CreatedTimestamp":"1515061889","DelaySeconds":"0","VisibilityTimeout":"600","ApproximateNumberOfMessages":"0","ApproximateNumberOfMessagesNotVisible":"0","LastModifiedTimestamp":"1515061889","QueueArn":"arn:aws:sqs:elasticmq:000000000000:test-api-log"}}

Can you spot any errors ?

Regards,
Harish

@adamw
Copy link
Member

adamw commented Jan 5, 2018 via email

@dsiegal
Copy link

dsiegal commented Mar 6, 2018

I just ran into the same issue. If I create a queue with a redrive policy and then query its attributes, the redrive policy is not among them. This differs from AWS. However the good news is that in my own testing, the redrive policy is actually in effect; messages are failing over after the maxReceiveCount number of receives. But it would be nice to query a queue regarding its redrive policy. Thanks.

simong added a commit to simong/elasticmq that referenced this issue Mar 7, 2018
simong added a commit to simong/elasticmq that referenced this issue Mar 13, 2018
adamw added a commit that referenced this issue Mar 14, 2018
#124 - Output RedrivePolicy attributes
@jaxley
Copy link

jaxley commented Apr 2, 2018

When is 0.13.9 set to release? I see the standalone version is up on S3 and linked to from this repository, but there isn't any official release to the maven repos yet.

@adamw
Copy link
Member

adamw commented Apr 2, 2018

@jaxley sorry, my bad - somehow this step slipped :) Should be in central in ~15 minutes!

@jaxley
Copy link

jaxley commented Apr 2, 2018

Thanks. But there's at least one bug in the code. RedrivePolicy is still listed as an unsupported attribute name.

object UnsupportedAttributeNames {
    val PolicyAttribute = "Policy"
    val MaximumMessageSizeAttribute = "MaximumMessageSize"
    val MessageRetentionPeriodAttribute = "MessageRetentionPeriod"
    val RedrivePolicyAttribute = "RedrivePolicy"

    val AllUnsupportedAttributeNames = PolicyAttribute :: MaximumMessageSizeAttribute ::
      MessageRetentionPeriodAttribute :: RedrivePolicyAttribute :: Nil
  }

This code triggers that, so should probably be mirrored in one of the unit tests to make sure it works properly:

final SetQueueAttributesRequest queueAttributesRequest = new SetQueueAttributesRequest()
                    .withQueueUrl(client.getQueueUrl("my-listener")
                            .getQueueUrl())
                    .addAttributesEntry("RedrivePolicy", JSON.toString(redriveSettings));

simong added a commit to simong/elasticmq that referenced this issue Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants