1

I'm trying to create a new queue, but when using

cf create-service aws-sqs standard my-q

the name of the queue in AWS is automatically assigned and is just an id composed of random letters and numbers.

This is fine when using the normal java client. However, we want to use spring-cloud-aws-messaging (@SqsListener annotation), because it offers us deletion policies out of the box, and a way to extend visibility, so that we can implement retries easily.

    @SqsListener(value = "my-q", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
    public void listen(TestItem item, Visibility visibility) {
        log.info("received message: " + item);

        //do business logic
        //if call fails
        visibility.extend(1000);
        //throw exception

        //if no failure, message will be dropped
    }

The queue name on the annotation is declared, so we can't change it dynamically after reading the VCAP_SERVICE environment variable injected by PCF on the application.

The only alternative we can think of is use reflection to set accessibility on value of the annotation, and set the value to the name on the VCAP_SERVICE, but that's just nasty, and we'd like to avoid it if possible.

Is there any way to change the name of the queue to something specific on creation? This suggests that it's possible, as seen below:

cf create-service aws-sqs standard my-q -c '{ "CreateQueue": {  "QueueName": “my-q”, "Attributes": { "MaximumMessageSize": "1024"} } }'

However, this doesn't work. It returns:

Incorrect Usage: Invalid configuration provided for -c flag. Please provide a valid JSON object or path to a file containing a valid JSON object.

How do I set the name on creation of the queue? Or the only way to achieve my end goal is to use reflection?

EDIT: As pointed out by Daniel Mikusa, the double quotes were not real double quotes, and that was causing the error. The command is successful now, however it doesn't create the queue with the intended name. I'm now wondering if this name needs to be set on bind-service instead. The command has a -c option too but I cannot find any documentation to support which parameters are available for a aws-sqs service.

redwulf
  • 1,317
  • 3
  • 13
  • 35
  • 1
    Using `cf create-service -c` is the way to go. There's something it doesn't like about your JSON. When I copy & paste your JSON into a validator, it fails. It look like the quote characters around the name `my-q` are not simple double quotes. If I delete those and replace them with regular double quote characters then it's valid. Maybe give that a try? Otherwise, maybe look at the shell your using? You could try putting it in a file and `cf create-service -c path/to/file.json` instead. – Daniel Mikusa Apr 07 '19 at 18:45
  • The command works and the queue is created, but still doesn't seem to change the name of the queue, unfortunately. When I go to PCF, I still see a random id in the name and url – redwulf Apr 08 '19 at 09:39
  • The docs seem pretty clear that it's supposed to be passed into the `cf create-service` command. I did a quick look through the broker's source code but I don't see it reading the queue name property when it's provisioning the service. It seems to only read what's under the `Attributes` block, so it seems like a docs bug (or at least that property isn't being used in an obvious way). From what I can see queue name is made by a prefix + the service instance guid, which seems to match what you're seeing. I'm not an expert on that code though, so I could be missing something. – Daniel Mikusa Apr 08 '19 at 15:25
  • 1
    My suggestion would be to contact Pivotal Support. They can get you more help and dig in more. Best case I missed something and there is a way to set the queue name. Worst case, they can update the docs & log a feature request for you. What you're trying to do seems reasonable to me. – Daniel Mikusa Apr 08 '19 at 15:27

0 Answers0