use of org.springframework.amqp.rabbit.annotation.RabbitListener in project codekvast by crispab.
the class AbstractCodekvastEventListener method onMessage.
@RabbitListener(queues = CODEKVAST_EVENT_QUEUE, ackMode = "AUTO")
@Transactional(rollbackFor = Exception.class)
public void onMessage(Message message, @Payload CodekvastEvent event) throws Exception {
logger.debug("Received {}", message);
Instant startedAt = clock.instant();
MessageProperties messageProperties = message.getMessageProperties();
CorrelationIdHolder.set(messageProperties.getCorrelationId());
try {
messageIdRepository.rememberMessageId(messageProperties.getMessageId());
onCodekvastEvent(event);
} catch (DuplicateMessageIdException e) {
logger.warn("Attempt to re-process already processed message {}", message);
} catch (Exception e) {
logger.error("Failed to process " + event, e);
// Move the message to the DLQ for later inspection
throw e;
} finally {
CorrelationIdHolder.clear();
metricsService.recordEventConsumed(consumerName, event, Duration.between(startedAt, clock.instant()));
}
}
use of org.springframework.amqp.rabbit.annotation.RabbitListener in project daijie-example by daijiejay.
the class ConsumerTest method process.
@RabbitHandler
@RabbitListener(queues = "hello")
public void process(Message message) {
byte[] body = message.getBody();
User user = (User) SerializeUtil.deserialize(body);
System.out.println(user.getUserName());
}
Aggregations