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

时间:2025-02-12 14:55:13

消费消息

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;@Componentpublic 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
提示

您即将访问非华为云网站,请注意账号财产安全