Skip to content

Commit 9038e87

Browse files
Bugfix -> SNS consumer queue name is always undefined (#128)
* Fixing queueName on SNS consumer * Adding tests to cover the bugfix * SNS patch version * Fixing typo Co-authored-by: Igor Savin <[email protected]> --------- Co-authored-by: Igor Savin <[email protected]>
1 parent dc8470e commit 9038e87

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

packages/sns/lib/sns/AbstractSnsSqsConsumer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export abstract class AbstractSnsSqsConsumer<
9898
this.subscriptionConfig,
9999
{ logger: this.logger },
100100
)
101+
this.queueName = initSnsSqsResult.queueName
101102
this.queueUrl = initSnsSqsResult.queueUrl
102103
this.topicArn = initSnsSqsResult.topicArn
103104
this.subscriptionArn = initSnsSqsResult.subscriptionArn

packages/sns/lib/utils/snsInitter.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export async function initSnsSqs(
3131
'If locatorConfig.subscriptionArn is not specified, creationConfig.queue parameter is mandatory, as there will be an attempt to create the missing queue',
3232
)
3333
}
34+
if (!creationConfig.queue.QueueName) {
35+
throw new Error('If locatorConfig.subscriptionArn is not specified, creationConfig.queue.QueueName parameter is mandatory, as there will be an attempt to create the missing queue')
36+
}
3437
if (!subscriptionConfig) {
3538
throw new Error(
3639
'If locatorConfig.subscriptionArn is not specified, subscriptionConfig parameter is mandatory, as there will be an attempt to create the missing subscription',
@@ -58,12 +61,12 @@ export async function initSnsSqs(
5861
return {
5962
subscriptionArn,
6063
topicArn,
64+
queueName: creationConfig.queue.QueueName,
6165
queueUrl,
6266
}
6367
}
6468

6569
// Check for existing resources, using the locators
66-
6770
const queuePromise = getQueueAttributes(sqsClient, locatorConfig)
6871
const topicPromise = getTopicAttributes(snsClient, locatorConfig.topicArn)
6972

@@ -76,10 +79,14 @@ export async function initSnsSqs(
7679
throw new Error(`Topic with topicArn ${locatorConfig.topicArn} does not exist.`)
7780
}
7881

82+
const splitUrl = locatorConfig.queueUrl.split('/')
83+
const queueName = splitUrl[splitUrl.length - 1]
84+
7985
return {
8086
subscriptionArn: locatorConfig.subscriptionArn,
8187
topicArn: locatorConfig.topicArn,
8288
queueUrl: locatorConfig.queueUrl,
89+
queueName,
8390
}
8491
}
8592

packages/sns/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@message-queue-toolkit/sns",
3-
"version": "13.0.0",
3+
"version": "13.0.1",
44
"private": false,
55
"license": "MIT",
66
"description": "SNS adapter for message-queue-toolkit",

packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe('SnsSqsPermissionConsumer', () => {
6868
expect(newConsumer.subscriptionProps.queueUrl).toBe(
6969
'http://s3.localhost.localstack.cloud:4566/000000000000/existingQueue',
7070
)
71+
expect(newConsumer.subscriptionProps.queueName).toBe('existingQueue')
7172
expect(newConsumer.subscriptionProps.topicArn).toEqual(arn)
7273
expect(newConsumer.subscriptionProps.subscriptionArn).toBe(
7374
'arn:aws:sns:eu-west-1:000000000000:user_permissions:bdf640a2-bedf-475a-98b8-758b88c87395',
@@ -106,6 +107,7 @@ describe('SnsSqsPermissionConsumer', () => {
106107
expect(newConsumer.subscriptionProps.queueUrl).toBe(
107108
'http://sqs.eu-west-1.localstack:4566/000000000000/existingQueue',
108109
)
110+
expect(newConsumer.subscriptionProps.queueName).toBe('existingQueue')
109111

110112
const attributes = await getQueueAttributes(sqsClient, {
111113
queueUrl: newConsumer.subscriptionProps.queueUrl,
@@ -152,6 +154,7 @@ describe('SnsSqsPermissionConsumer', () => {
152154
const attributes = await getQueueAttributes(sqsClient, {
153155
queueUrl: newConsumer.subscriptionProps.queueUrl,
154156
})
157+
expect(newConsumer.subscriptionProps.queueName).toBe('existingQueue')
155158

156159
expect(attributes.result?.attributes!.Policy).toBe(
157160
'{"Version":"2012-10-17","Id":"__default_policy_ID","Statement":[{"Sid":"AllowSNSPublish","Effect":"Allow","Principal":{"AWS":"*"},"Action":"sqs:SendMessage","Resource":"arn:aws:sqs:eu-west-1:000000000000:existingQueue","Condition":{"ArnLike":{"aws:SourceArn":"someservice-"}}}]}',
@@ -181,6 +184,7 @@ describe('SnsSqsPermissionConsumer', () => {
181184
expect(newConsumer.subscriptionProps.queueUrl).toBe(
182185
'http://sqs.eu-west-1.localstack:4566/000000000000/existingQueue',
183186
)
187+
expect(newConsumer.subscriptionProps.queueName).toBe('existingQueue')
184188

185189
const attributes = await getQueueAttributes(sqsClient, {
186190
queueUrl: newConsumer.subscriptionProps.queueUrl,

packages/sns/test/consumers/SnsSqsPermissionConsumer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export class SnsSqsPermissionConsumer extends AbstractSnsSqsConsumer<
170170
return {
171171
topicArn: this.topicArn,
172172
queueUrl: this.queueUrl,
173+
queueName: this.queueName,
173174
subscriptionArn: this.subscriptionArn,
174175
deadLetterQueueUrl: this.deadLetterQueueUrl,
175176
}

0 commit comments

Comments
 (0)