- The property
prehandlers
has been updated topreHandler
for consumers. - In the SQS and SNS consumer,
consumerOverrides
no longer permits the alteration of critical properties such assqs
,queueUrl
,handler
, andhandleMessageBatch
to prevent confusion and maintain proper functionality of the consumer. - The
consumerOverrides
in the SQS and SNS consumer no longer includes the option to define thevisibilityTimeout
property, as it is now automatically determined by the consumer from thecreationConfig
or queue configuration in the case oflocatorConfig
.
If you currently utilize the prehandlers
property in your consumer, it will be necessary to update it to preHandler
.
If you are implementing the consumerOverrides
property in your consumer, it is essential to eliminate the properties
sqs
, queueUrl
, handler
, handleMessageBatch
, and visibilityTimeout
.
sqs
should be included in the constructor dependenciesqueueUrl
is managed automatically by the library and does not require manual specificationhandleMessageBatch
is not supported by the libraryvisibilityTimeout
is automatically managed by the library and does not need explicit declaration- For the
handler
, use thehandler
property in the constructor as demonstrated below
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 },
},
messageTypeField: 'messageType',
handlers: new MessageHandlerConfigBuilder<SupportedEvents, ExecutionContext>()
.addConfig(
MY_MESSAGE_SCHEMA,
async (message) => {
// Your handling code
return {
result: 'success',
}
},
)
.build(),
},
undefined
)
}
}
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.
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
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.
- Rename the class you are extending from
AbstractSqsPublisherMonoSchema
toAbstractSqsPublisherSchema
. - replace the
messageSchema
property withmessageSchemas
, it is an array ofzod
schemas.
// 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',
})
}
}
- Rename the class you are extending from
AbstractSqsConsumerMonoSchema
toAbstractSqsConsumer
. - Remove the
messageSchema
property. - Define a handler (
handlers
property) for your message, specifying thezod
schema (oldmessageSchema
) and the method to handle the message (oldprocessMessage
method)
// 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 to see how to update your code.