feat: add support for custom SQS endpoint#2458
Open
maxir143 wants to merge 2 commits intoEvolutionAPI:mainfrom
Open
feat: add support for custom SQS endpoint#2458maxir143 wants to merge 2 commits intoEvolutionAPI:mainfrom
maxir143 wants to merge 2 commits intoEvolutionAPI:mainfrom
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds optional support for a custom SQS endpoint (e.g., Localstack) by wiring a new SQS_ENDPOINT env var through configuration, SQS client initialization, and queue URL construction while preserving existing default AWS behavior when not set. Sequence diagram for publishing SQS message with optional custom endpointsequenceDiagram
actor User
participant Service
participant ConfigService
participant SqsController
participant AwsSQS as Aws_SQS_SDK
User->>Service: triggerEvent(event, payload)
Service->>ConfigService: getSqsConfig()
ConfigService-->>Service: Sqs config (includes ENDPOINT)
Service->>SqsController: publishEvent(event, payload, extra)
SqsController->>SqsController: initializeSqs() with REGION and ENDPOINT
alt Custom endpoint provided
SqsController->>SqsController: buildQueueUrl() using ENDPOINT without trailing slash
else Default AWS endpoint
SqsController->>SqsController: buildQueueUrl() using https://sqs.REGION.amazonaws.com
end
SqsController->>AwsSQS: sendMessage(queueUrl, message)
AwsSQS-->>SqsController: sendMessageResult
SqsController-->>Service: publishEvent result
Service-->>User: event processed
Updated class diagram for SQS configuration and controllerclassDiagram
class Sqs {
+string ACCESS_KEY_ID
+string SECRET_ACCESS_KEY
+string ACCOUNT_ID
+string REGION
+string ENDPOINT
+number MAX_PAYLOAD_SIZE
}
class ConfigService {
+getSqsConfig() Sqs
}
class SqsController {
-Sqs awsConfig
-Sqs sqsConfig
-SQS sqsClient
+constructor(configService ConfigService)
+initializeSqs() void
+publishEvent(event string, payload any, extra any) Promise~void~
-buildQueueUrl(event string, prefixName string) string
}
ConfigService --> Sqs : returns
SqsController --> ConfigService : uses
SqsController --> Sqs : reads configuration
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider making
Sqs.ENDPOINToptional (ENDPOINT?: string) and defaulting it toundefinedinstead of''inConfigServiceso you can avoid relying on truthiness checks and keep the type aligned with how it’s used when passing to the SQS client. - The URL construction for custom endpoints assumes the endpoint does not already contain the account ID path; if users might pass a fully qualified LocalStack URL, you may want to either document that constraint or add a small normalization/validation helper to avoid double-appending the account ID.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider making `Sqs.ENDPOINT` optional (`ENDPOINT?: string`) and defaulting it to `undefined` instead of `''` in `ConfigService` so you can avoid relying on truthiness checks and keep the type aligned with how it’s used when passing to the SQS client.
- The URL construction for custom endpoints assumes the endpoint does not already contain the account ID path; if users might pass a fully qualified LocalStack URL, you may want to either document that constraint or add a small normalization/validation helper to avoid double-appending the account ID.
## Individual Comments
### Comment 1
<location path="src/api/integrations/event/sqs/sqs.controller.ts" line_range="129-130" />
<code_context>
: `${event.replace('.', '_').toLowerCase()}`;
const queueName = `${prefixName}_${eventFormatted}.fifo`;
- const sqsUrl = `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
+ const sqsUrl = sqsConfig.ENDPOINT
+ ? `${sqsConfig.ENDPOINT.replace(/\/$/, '')}/${sqsConfig.ACCOUNT_ID}/${queueName}`
+ : `https://sqs.${sqsConfig.REGION}.amazonaws.com/${sqsConfig.ACCOUNT_ID}/${queueName}`;
</code_context>
<issue_to_address>
**nitpick:** Normalize endpoint more robustly when stripping trailing slashes.
`replace(/\/$/, '')` only strips one trailing slash, so an endpoint like `http://localhost:4566///` would still produce extra slashes before the account ID. Using `replace(/\/+$/, '')`, the `URL` API, or a small normalization helper would make this more robust and avoid subtle URL issues.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Description
Add support for custom endpoint at SQS enabling users to use localstack endpoint, config, set it and clean the endpoint from environment variables, if not, fallback to default behaviour.
🔗 Related Issue
Closes #(issue_number)
🧪 Type of Change
🧪 Testing
📸 Screenshots (if applicable)
✅ Checklist
📝 Additional Notes
Summary by Sourcery
Add configurable support for custom SQS endpoints while preserving existing default behavior.
New Features: