Skip to content

Events

Este documento detalla los topics de SNS utilizados en el microservicio de Logística Inversa.

El microservicio de Logística Inversa utiliza AWS Simple Notification Service (SNS) para implementar un sistema de mensajería publicador/suscriptor. Este sistema permite al microservicio notificar a otros servicios sobre cambios en los elementos de logística inversa, como cuando se crean, cancelan, completan elementos, o cuando se reportan productos como faltantes, no recogidos o desperdiciados.

El microservicio utiliza el patrón Observer para publicar eventos en topics de SNS cuando se realizan diversas acciones en los elementos de logística inversa. Los eventos se publican utilizando la interfaz ReverseLogisticsEventDispatcher, que es implementada por la clase SnsReverseLogisticsEventDispatcher.

Nombre: TOPIC_MISSING_PRODUCT_ARN

ARN en Production:

arn:aws:sns:us-east-1:849786826922:reverse-logistic-missing-product-topic

ARN en Staging:

arn:aws:sns:us-east-2:529305108461:reverse-logistic-missing-product-topic

Propósito: Notificar a otros servicios cuando se reporta un producto como faltante en un elemento de logística inversa.

Productores:

  • Observer MissingReportEmitter, activado por casos de uso que reportan productos como faltantes

Formato del mensaje:

export interface MissingProductEvent {
type: 'MissingProduct'
data: {
itemId: string
itemType: string
productEan: string
productSku: string
productName: string
productZone: string
quantity: number
pendingQuantity: number
priority: number
status: string
user: string
taraId?: string
taraBarcode?: string
orderNumber?: string
target?: string
reportId?: string
timestamp: string
}
}

Nombre: TOPIC_UNPICK_PRODUCT_ARN

ARN en Production:

arn:aws:sns:us-east-1:849786826922:reverse-logistic-unpick-product-topic

ARN en Staging:

arn:aws:sns:us-east-2:529305108461:reverse-logistic-unpick-product-topic

Propósito: Notificar a otros servicios cuando un producto no es recogido en un elemento de logística inversa.

Productores:

  • Observer UnpickEmitter, activado por casos de uso que marcan productos como no recogidos

Formato del mensaje:

export interface UnpickProductEvent {
type: 'UnpickProduct'
data: {
itemId: string
itemType: string
productEan: string
productSku: string
productName: string
productZone: string
quantity: number
pendingQuantity: number
priority: number
status: string
user: string
taraId?: string
taraBarcode?: string
orderNumber?: string
target?: string
reportId?: string
timestamp: string
}
}

Nombre: TOPIC_WASTE_PRODUCT_ARN

ARN en Production:

arn:aws:sns:us-east-1:849786826922:reverse-logistic-waste-product-topic

ARN en Staging:

arn:aws:sns:us-east-2:529305108461:reverse-logistic-waste-product-topic

Propósito: Notificar a otros servicios cuando un producto se reporta como desperdicio en un elemento de logística inversa.

Productores:

  • Observer WasteReportEmitter, activado por casos de uso que reportan productos como desperdicio

Formato del mensaje:

export interface WasteProductEvent {
type: 'WasteProduct'
data: {
itemId: string
itemType: string
productEan: string
productSku: string
productName: string
productZone: string
quantity: number
pendingQuantity: number
priority: number
status: string
user: string
taraId?: string
taraBarcode?: string
orderNumber?: string
target?: string
reportId?: string
timestamp: string
}
}

Nombre: TOPIC_ITEM_CANCELLED_ARN

ARN en Production:

arn:aws:sns:us-east-1:849786826922:reverse-logistic-item-cancelled-topic

ARN en Staging:

arn:aws:sns:us-east-2:529305108461:reverse-logistic-item-cancelled-topic

Propósito: Notificar a otros servicios cuando se cancela un elemento de logística inversa.

Productores:

  • Observer ItemCancelledEmitter, activado por el caso de uso CancelReverseLogisticItem

Formato del mensaje:

export interface ItemCancelledEvent {
type: 'ItemCancelled'
data: {
itemId: string
type: ReverseLogisticType
status: ReverseLogisticStatus
priority: Priority
products: Array<{
ean: string
sku?: string
name?: string
zone: Zone
quantity: number
priority: Priority
isSampling: boolean
unpicks?: Array<{
timestamp: string
quantity: number
target: string
user: string
}>
wasteReports?: Array<{
reportId: string
timestamp: string
quantity: number
user: string
}>
missingReports?: Array<{
timestamp: string
quantity: number
user: string
}>
}>
tara?: {
id: string
barcode: string
orderNumber: string
}
createdAt: string
cancelledAt?: string
completedAt?: string
}
}

Nombre: TOPIC_ITEM_COMPLETED_ARN

ARN en Production:

arn:aws:sns:us-east-1:849786826922:reverse-logistic-item-completed-topic

ARN en Staging:

arn:aws:sns:us-east-2:529305108461:reverse-logistic-item-completed-topic

Propósito: Notificar a otros servicios cuando se completa un elemento de logística inversa.

Productores:

  • Observer ItemCompletedEmitter, activado por casos de uso que completan elementos

Formato del mensaje:

export interface ItemCompletedEvent {
type: 'ItemCompleted'
data: {
itemId: string
type: ReverseLogisticType
status: ReverseLogisticStatus
priority: Priority
products: Array<{
ean: string
sku?: string
name?: string
zone: Zone
quantity: number
priority: Priority
isSampling: boolean
unpicks?: Array<{
timestamp: string
quantity: number
target: string
user: string
}>
wasteReports?: Array<{
reportId: string
timestamp: string
quantity: number
user: string
}>
missingReports?: Array<{
timestamp: string
quantity: number
user: string
}>
}>
tara?: {
id: string
barcode: string
orderNumber: string
}
createdAt: string
cancelledAt?: string
completedAt?: string
}
}

Nombre: TOPIC_ITEM_CREATED_ARN

ARN en Production:

arn:aws:sns:us-east-1:849786826922:reverse-logistic-item-created-topic

ARN en Staging:

arn:aws:sns:us-east-2:529305108461:reverse-logistic-item-created-topic

Propósito: Notificar a otros servicios cuando se crea un elemento de logística inversa.

Productores:

  • Observer ItemCreatedEmitter, activado por el caso de uso CreateReverseLogisticItem

Formato del mensaje:

export interface ItemCreatedEvent {
type: 'ItemCreated'
data: {
itemId: string
type: ReverseLogisticType
status: ReverseLogisticStatus
priority: Priority
products: Array<{
ean: string
sku?: string
name?: string
zone: Zone
quantity: number
priority: Priority
isSampling: boolean
unpicks?: Array<{
timestamp: string
quantity: number
target: string
user: string
}>
wasteReports?: Array<{
reportId: string
timestamp: string
quantity: number
user: string
}>
missingReports?: Array<{
timestamp: string
quantity: number
user: string
}>
}>
tara?: {
id: string
barcode: string
orderNumber: string
}
createdAt: string
cancelledAt?: string
completedAt?: string
}
}

El manejo de errores y reintentos se implementa de la siguiente manera:

  1. Registro de errores:

    • Todos los errores de publicación se registran utilizando el sistema de logging. Ejemplo:
      src/app/observers/sns/create-emitter.ts
      logger.error({
      event: ItemCreatedEmitter.name,
      err,
      msg: err.message,
      data: { itemId: item.id.toString() }
      })
  2. Manejo de errores:

    • Se utiliza la clase EitherAsync para el manejo de errores, permitiendo una propagación limpia de errores.
    • Los errores se envuelven en las clases BusinessError o UnexpectedError.
    • La función handleError se utiliza para estandarizar el manejo de errores en toda la aplicación.