RabbitListener ack or nack code example
Example: spring AMQP async nack
@Bean
fun jsaFactory(
connectionFactory: ConnectionFactory,
configurer: SimpleRabbitListenerContainerFactoryConfigurer
): SimpleRabbitListenerContainerFactory {
val factory = SimpleRabbitListenerContainerFactory()
factory.setAcknowledgeMode(AcknowledgeMode.MANUAL)
factory.setMessageConverter(jsonMessageConverter())
configurer.configure(factory, connectionFactory)
return factory
}
@RabbitListener(queues = ["salesforce.contact-courses.update"])
fun update(message: CourseRequestDto): Mono<Void> {
message.email ?: return Mono.error<Void>(AmqpRejectAndDontRequeueException("Invalid message received"))
return courseDtoBuilder.getInstance(message)
.flatMap { contactRestClient.coursePatch(message.email, it) }
.doOnError { throw AmqpRejectAndDontRequeueException(it.message) }
}