My RMQ listener:
@RabbitListener(
bindings = @QueueBinding(
value = @Queue,
exchange = @Exchange(
value = "${rabbitmq.exchange.sales-exchange.name}",
type = "${rabbitmq.exchange.sales-exchange.type}",
ignoreDeclarationExceptions = "true"
),
key = "${rabbitmq.exchange.sales-exchange.sales-bk}"
)
)
public void listenSalesOrderCreatedMessage(
@Headers Map<String, Object> headers,
@Payload SalesDTO payload
)
{
log.info("Message Received!");
}
salesDTO:
package org.laptop.sale.event.subscriber.dto;
@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
@Setter
public class SalesOrderCreatedEventDTO implements Serializable {
@JsonProperty("vendorDetails")
@Valid
private VendorDetails vendorDetails;
@JsonInclude(JsonInclude.Include.NON_NULL)
@Getter
@Setter
public static class VendorDetails implements Serializable {
@JsonProperty("name")
private String name;
@JsonProperty("vendorCommission")
private Double vendorCommission;
}
}
My @Around Aspect to be executed before and after the message call:
package org.laptop.sale.event.subscriber;
@Component
@Aspect
@Slf4j
public class SubscriberAdvice {
@Around("execution(* org.laptop.sale.event.subscriber..*(..)))")
public void payloadValidationFailed(ProceedingJoinPoint joinPoint) {
try {
joinPoint.proceed();
} catch (Throwable throwable) {
log.error("Exception in the process execution {}", throwable);
}
}
}
Invalid Message payload:
{
"vendorDetails": {
"name": "Vendor Name",
"vendorCommission": "wrongData"
}
}
Valid Message payload:
{
"vendorDetails": {
"name": "Vendor Name",
"vendorCommission": 8000.1
}
}
Here the the program flow is entering the aspect only incase of Valid payload. It's not entering the Aspect incase of Invalid Payload. I tried with @AfterThrowing as well. that did not work either