分布式消息服务RABBITMQ版-使用Spring Boot连接RabbitMQ实例:消费消息

时间:2024-11-05 17:02:32

消费消息

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;


@Component
public class ReceiveMsgService {
    Logger  LOG  =  LoggerFactory.getLogger(ReceiveMsgService.class);

    @RabbitListener(queues = "test")
    public void receive(String message) {
        SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        LOG.info("receive message: {}", message + " 接收时间:" + simpleDateFormat.format(new Date()));
    }
}
support.huaweicloud.com/devg-rabbitmq/rabbitmq-devg-005.html