Skip to content
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

reapply Moment-Wealth-master #204

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/bus-sqs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"access": "public"
},
"dependencies": {
"@aws-sdk/client-sns": "^3.321.1",
"@aws-sdk/client-sqs": "^3.321.1",
"@aws-sdk/util-arn-parser": "^3.310.0",
"@node-ts/bus-messages": "^1.0.4",
"aws-sdk": "^2.1368.0",
"tslib": "^1.9.3",
"uuid": "^3.3.2"
},
Expand Down
11 changes: 7 additions & 4 deletions packages/bus-sqs/src/queue-resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SqsTransportConfiguration } from './sqs-transport-configuration'

const invalidSqsSnsCharacters = new RegExp('[^a-zA-Z0-9_-]', 'g')
export const normalizeMessageName = (messageName: string) =>
messageName.replace(invalidSqsSnsCharacters, '-')
Expand All @@ -24,13 +26,14 @@ export const resolveTopicArn = (
) => `arn:aws:sns:${awsRegion}:${awsAccountId}:${topicName}`

export const resolveQueueUrl = (
href: string,
awsAccountId: string,
{ awsAccountId, awsRegion }: SqsTransportConfiguration,
queueName: string
) => `${href}${awsAccountId}/${queueName}`
) => `https://sqs.${awsRegion}.amazonaws.com/${awsAccountId}/${queueName}`

export const resolveQueueArn = (
awsAccountId: string,
awsRegion: string,
queueName: string
) => `arn:aws:sqs:${awsRegion}:${awsAccountId}:${queueName}`
export const resolveDeadLetterQueueName = () => `dead-letter-queue`

export const resolveDeadLetterQueueName = () => `dlq`
24 changes: 21 additions & 3 deletions packages/bus-sqs/src/sqs-transport-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,41 @@ import {
resolveTopicName as defaultResolveTopicName
} from './queue-resolvers'

export interface SqsTransportConfiguration extends TransportConfiguration {
export interface SqsTransportConfiguration
extends Omit<TransportConfiguration, 'queueName'> {
/**
* The AWS Account Id of the account where queues and topics will be created
*/
awsAccountId: string
awsAccountId?: string

/**
* The AWS region to create queues and topics in
*/
awsRegion: string
awsRegion?: string

/**
* An optional AWS ARN of the dead letter queue to fail messages to
* @default undefined
*/
deadLetterQueueArn?: string

/**
* The number of seconds to retain messages in the service and dead letter queues
* @default 1209600 (14 days)
*/
messageRetentionPeriod?: number

/**
* The AWS ARN for the target SQS Queue
*/
queueArn?: string

/**
* The name of the queue that receives incoming messages
* @example order-booking-service
*/
queueName?: string

/**
* An optional custom queue policy to apply to any created SQS queues.
* By default a generic policy will be added that grants send permissions to SNS
Expand Down
30 changes: 22 additions & 8 deletions packages/bus-sqs/src/sqs-transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import {
toMessageAttributeMap,
SqsMessageAttributes,
fromMessageAttributeMap,
SqsTransport
SqsTransport,
SnsMessageAttributeMap
} from './sqs-transport'
import { SNS, SQS } from 'aws-sdk'
import {
ChangeMessageVisibilityCommand,
SQSClient,
Message as SQSMessage
} from '@aws-sdk/client-sqs'
import { MessageAttributes } from '@node-ts/bus-messages'
import * as faker from 'faker'
import { SqsTransportConfiguration } from './sqs-transport-configuration'
Expand Down Expand Up @@ -67,7 +72,7 @@ describe('sqs-transport', () => {
}
}

let messageAttributes: SNS.MessageAttributeMap
let messageAttributes: SnsMessageAttributeMap

beforeEach(() => {
messageAttributes = toMessageAttributeMap(messageOptions)
Expand Down Expand Up @@ -108,8 +113,15 @@ describe('sqs-transport', () => {

describe('when returning a message to the queue', () => {
it('should use the retry strategy delay', async () => {
const sqs = Mock.ofType(SQS)
const sut = new SqsTransport({} as SqsTransportConfiguration, sqs.object)
const sqs = Mock.ofType(SQSClient)
const sut = new SqsTransport(
{
awsAccountId: '1',
awsRegion: 'us-west-2',
queueName: 'abc'
} as SqsTransportConfiguration,
sqs.object
)

const retryStrategy: RetryStrategy = {
calculateRetryDelay() {
Expand All @@ -124,14 +136,16 @@ describe('sqs-transport', () => {

sqs
.setup(s =>
s.changeMessageVisibility(
It.isObjectWith<any>({ VisibilityTimeout: 3 })
s.send(
It.is<ChangeMessageVisibilityCommand>(
x => x.input.VisibilityTimeout === 3
)
)
)
.returns(() => ({ promise: async () => undefined } as any))
.verifiable(Times.once())

await sut.returnMessage({ raw: {} } as TransportMessage<SQS.Message>)
await sut.returnMessage({ raw: {} } as TransportMessage<SQSMessage>)
sqs.verifyAll()
})
})
Expand Down
Loading