Automatically subscribing a queue to a topic fails.

60 views
Skip to first unread message

rame...@familysearch.org

unread,
Nov 14, 2014, 1:38:51 PM11/14/14
to cmb-use...@googlegroups.com
We have been trying to automatically subscribe a queue to a topic through the the aws sdk (1.6.12) and it is failing at the subscribeQueue call. This same call works with the amazon api.  We have written a simple app that shows this functionality working in AWS and failing with CMB.
Main.java

boriwo

unread,
Nov 25, 2014, 5:48:22 PM11/25/14
to cmb-use...@googlegroups.com
We checked this out and there is no bug here - your just need to adjust your code slightly.

Here is the issue: When subscribing a queue to a topic in CMB you need to distinguish between two protocols, "sqs" (referring to an queue in AWS) and "cqs" (referring to a queue in CMB). In AWS you don't have to make this distinction because queues are always SQS queues!

Unfortunately, the client API you are using in your example (Topics.subscribeQueue()) defaults to assume you are referring to a queue in SQS which of course does not exist and results in an error.

If instead of 

  Topics.subscribeQueue(amazonSNSClient, amazonSQSClient, createTopicResult.getTopicArn(), createQueueResult.getQueueUrl());

you write

  String queueUrl = createQueueResult.getQueueUrl();
  String queueArn = com.comcast.cqs.util.Util.getArnForAbsoluteQueueUrl(queueUrl);
  amazonSNSClient.subscribe(createTopicResult.getTopicArn(), "cqs", queueArn);

everything works as it should.

Note: The protocol specified here is "cqs" and not "sqs"! Also note, that subscribe() takes a queue ARN as parameter and not a queue URL. I'm using a CMB util function here to convert the queue URL to an ARN. Finally, if you provide proper AWS credentials in cmb.properties you can also subscribe to SQS queues and publish from a CNS topic into a SQS queue.


Reply all
Reply to author
Forward
0 new messages