-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mono publisher and consumer removal (#112)
* Removing sqs mon publisher/consumer * core preparation for multi publishers only * SQS Abstract consumer * SQS publisher rename * SQS test fixes * Unused code removed * Fix lint * sqs Index fix + lint fix * Removing SNS mono consumer and publisher * Minor fix on sqs * SNS Fixing types * SNS renaming * SNS test fixes * amqp service types fix * amqp single publisher * amqp single consumer * removing unused tests * AMQP tests fixes * amqp index fix * Minor changes * Solving TODO * Minor change to not allow changing internal properties * SQS improving coverage * Adding tests * Lint fix * Removing unused test class * SQS making props protected * SNS marking some props as protected * Minor changes * AMQP improving tests coverage * Improving AMQP test coverage * Fix test * Trying to fix test * readme updated * Major version * Minor change * upgrading md * Lint fixes + solving todo + build fix * CR comments
- Loading branch information
1 parent
a47c67c
commit a176d75
Showing
74 changed files
with
1,756 additions
and
3,618 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# Upgrading Guide | ||
|
||
We have introduced the following breaking changes on version `12.0.0`, please follow the steps below to update your code | ||
from the previous version to the new one. | ||
|
||
## Breaking Changes | ||
|
||
### Description of Breaking Change | ||
Multi consumers and publishers can accomplish the same tasks as mono ones, but they add extra layer of complexity by | ||
requiring features to be implemented in both. | ||
As a result, we have decided to remove the mono ones to enhance maintainability. | ||
|
||
### Migration Steps | ||
#### Multi consumers and publishers | ||
If you are using the multi consumer or consumer, you will only need to rename the class you are extending, and it should | ||
work as before. | ||
- `AbstractSqsMultiConsumer` -> `AbstractSqsConsumer` | ||
- `AbstractSqsMultiPublisher` -> `AbstractSqsPublisher` | ||
|
||
#### Mono consumers and publishers | ||
If you are using the mono consumer or publisher, they no longer exist, so you will need to adjust your code to use | ||
the old named multi consumer or publisher (now called just consumer or publisher). Please check the guide below. | ||
|
||
##### Publisher | ||
1. Rename the class you are extending from `AbstractSqsPublisherMonoSchema` to `AbstractSqsPublisherSchema`. | ||
2. replace the `messageSchema` property with `messageSchemas`, it is an array of `zod` schemas. | ||
```typescript | ||
// Old code | ||
export class MyPublisher extends AbstractSqsPublisherMonoSchema<MyType> { | ||
public static QUEUE_NAME = 'my-queue-name' | ||
|
||
constructor(dependencies: SQSDependencies) { | ||
super(dependencies, { | ||
creationConfig: { | ||
queue: { | ||
QueueName: SqsPermissionPublisherMonoSchema.QUEUE_NAME, | ||
}, | ||
}, | ||
handlerSpy: true, | ||
deletionConfig: { | ||
deleteIfExists: false, | ||
}, | ||
logMessages: true, | ||
messageSchema: MY_MESSAGE_SCHEMA, | ||
messageTypeField: 'messageType', | ||
}) | ||
} | ||
} | ||
|
||
// Updated code | ||
export class MyPublisher extends AbstractSqsPublisher<MyType> { | ||
public static QUEUE_NAME = 'my-queue-name' | ||
|
||
constructor(dependencies: SQSDependencies) { | ||
super(dependencies, { | ||
creationConfig: { | ||
queue: { | ||
QueueName: SqsPermissionPublisherMonoSchema.QUEUE_NAME, | ||
}, | ||
}, | ||
handlerSpy: true, | ||
deletionConfig: { | ||
deleteIfExists: false, | ||
}, | ||
logMessages: true, | ||
messageSchemas: [MY_MESSAGE_SCHEMA], | ||
messageTypeField: 'messageType', | ||
}) | ||
} | ||
} | ||
``` | ||
|
||
##### Consumer | ||
1. Rename the class you are extending from `AbstractSqsConsumerMonoSchema` to `AbstractSqsConsumer`. | ||
2. Remove the `messageSchema` property. | ||
3. Define a handler (`handlers` property) for your message, specifying the `zod` schema (old `messageSchema`) and the | ||
method to handle the message (old `processMessage` method) | ||
```typescript | ||
// Old code | ||
export class MyConsumer extends AbstractAmqpConsumerMonoSchema<MyType> { | ||
public static QUEUE_NAME = 'my-queue-name' | ||
|
||
constructor(dependencies: AMQPConsumerDependencies) { | ||
super(dependencies, { | ||
creationConfig: { | ||
queueName: AmqpPermissionConsumer.QUEUE_NAME, | ||
queueOptions: { | ||
durable: true, | ||
autoDelete: false, | ||
}, | ||
}, | ||
deletionConfig: { | ||
deleteIfExists: true, | ||
}, | ||
messageSchema: MY_MESSAGE_SCHEMA, | ||
messageTypeField: 'messageType', | ||
}) | ||
} | ||
|
||
override async processMessage( | ||
message: MyType, | ||
): Promise<Either<'retryLater', 'success'>> { | ||
// Your handling code | ||
return { result: 'success' } | ||
} | ||
} | ||
|
||
// Updated code | ||
export class MyConsumer extends AbstractAmqpConsumer<MyType, undefined> { | ||
public static QUEUE_NAME = 'my-queue-name' | ||
|
||
constructor(dependencies: AMQPConsumerDependencies) { | ||
super( | ||
dependencies, | ||
{ | ||
creationConfig: { | ||
queueName: AmqpPermissionConsumer.QUEUE_NAME, | ||
queueOptions: { | ||
durable: true, | ||
autoDelete: false, | ||
}, | ||
}, | ||
deletionConfig: { | ||
deleteIfExists: true, | ||
}, | ||
messageTypeField: 'messageType', | ||
handlers: new MessageHandlerConfigBuilder<SupportedEvents, ExecutionContext>() | ||
.addConfig( | ||
MY_MESSAGE_SCHEMA, | ||
async (message) => { | ||
// Your handling code | ||
return { | ||
result: 'success', | ||
} | ||
}, | ||
) | ||
.build(), | ||
}, | ||
undefined | ||
) | ||
} | ||
} | ||
``` | ||
> **_NOTE:_** on this example code we are omitting the barrier pattern (`preHandlerBarrier`) and pre handlers (`preHandlers`) | ||
to simplify the example. If you are using them, please check [SqsPermissionConsumer.ts](./packages/sqs/test/consumers/SqsPermissionConsumer.ts) | ||
to see how to update your code. |
This file contains 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.