-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support a mix of locator and creation configs for SNS #210
base: main
Are you sure you want to change the base?
Conversation
@@ -85,6 +85,8 @@ export abstract class AbstractSnsSqsConsumer< | |||
this.creationConfig.queue, | |||
this.creationConfig.topic, | |||
this.subscriptionConfig, | |||
undefined, | |||
this.locatorConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS is complaining now that initSnsSqs().queueUrl
is string|undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kibertoad I solved this by adding if
to check if queue url is present. From the code it looks it should be mandatory parameter if subscriptionArn
is provided, we must provide queueUrl
too. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't there branching after the check you added, where we skip the queueUrl-related logic if it's not present?
we should support passing queueName instead of queueUrl, no? or we always resolve url based on name earlier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is branch with check, but it didn't guarantee that queueUrl
is present after that:
let queueName: string
if ((locatorConfig as SQSQueueLocatorType).queueUrl) {
const splitUrl = (locatorConfig as SQSQueueLocatorType).queueUrl.split('/')
queueName = splitUrl[splitUrl.length - 1]
} else {
queueName = creationConfig!.queue.QueueName!
}
return {
subscriptionArn: locatorConfig.subscriptionArn,
topicArn: subscriptionTopicArn,
queueUrl: locatorConfig.queueUrl,
queueName,
}
From this code it looks that queueUrl is mandatory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see it. if queueUrl is not present here, we will just return queueUrl: undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, but queueUrl
cannot be null. It's required in AbstractSnsSqsConsumer
, see line: 104
export type SNSSQSQueueLocatorType = SQSQueueLocatorType & | ||
SNSQueueLocatorType & { | ||
export type SNSSQSQueueLocatorType = Partial<SQSQueueLocatorType> & | ||
SNSTopicLocatorType & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How configuration in billing service could look like?
Arguments passed to constructor should be wrapped with isTest()
e.g.:
{
"creationConfig": isTest() ? { /* legit creation config */ } : undefined, //In production creation of topics will be disabled.
"locatorConfig": isTest() ? undefined : { /* legit locate config */ } //In production we will do read-only
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say that creationConfig would always have an entry for the queue, and conditionally will include entry for the topic.
locatorConfig will conditionally either have an entry for the topic, or be empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me visualize it with the test. I think the rest of the comments will clarify too.
|
||
return { | ||
subscriptionArn: locatorConfig.subscriptionArn, | ||
topicArn: locatorConfig.topicArn, | ||
topicArn: subscriptionTopicArn, | ||
queueUrl: locatorConfig.queueUrl, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it mix the configuration of both: locatorConfig
and creationConfig
? Both can be provided and we return queueName
from creation config but queue url comes from locate config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only follow this branch in case we ended up using locate config, but I might be wrong, worth checking
subscriptionConfiguration: SNSSubscriptionOptions, | ||
extraParams?: ExtraParams, | ||
topicLocator?: SNSTopicLocatorType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we rework this method and introduce a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
potentially. if you see a clear way to do this that would simplify the code, go for it
creationConfig?: SNSCreationConfig, | ||
) { | ||
if (locatorConfig) { | ||
const checkResult = await getTopicAttributes(snsClient, locatorConfig.topicArn) | ||
const topicArn = | ||
locatorConfig.topicArn ?? (await getTopicArnByName(snsClient, locatorConfig.topicName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed? It looks like new API not related to support both creation/locate configs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is needed to support both having a predefined arn and a lookup by topic name, which new logic relies upon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so precedence will always be:
- use ARN if present
- then resolve by name (async lookup)
EOR1 |
… just pass the whole configuration.
please review carefully, this was coded in a late night session using the scraps of the mental capacity, likely to be ugly and have gaps.
would be great to clean up the logic and split the code in the follow up prs.
implementation rushed to unblock Billinq service :-/