Search in sources :

Example 1 with RabbitListener

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()));
    }
}
Also used : MessageProperties(org.springframework.amqp.core.MessageProperties) Instant(java.time.Instant) RabbitListener(org.springframework.amqp.rabbit.annotation.RabbitListener) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RabbitListener

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());
}
Also used : User(org.daijie.mybatis.model.User) RabbitListener(org.springframework.amqp.rabbit.annotation.RabbitListener) RabbitHandler(org.springframework.amqp.rabbit.annotation.RabbitHandler)

Aggregations

RabbitListener (org.springframework.amqp.rabbit.annotation.RabbitListener)2 Instant (java.time.Instant)1 User (org.daijie.mybatis.model.User)1 MessageProperties (org.springframework.amqp.core.MessageProperties)1 RabbitHandler (org.springframework.amqp.rabbit.annotation.RabbitHandler)1 Transactional (org.springframework.transaction.annotation.Transactional)1