Spring Cloud Alibaba-07-RocketMQ消息驱动
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
@Component
@RocketMQMessageListener(topic = "YourTopic", consumerGroup = "YourConsumerGroup")
public class YourMessageListener implements RocketMQListener<String> {
@Override
public void onMessage(String message) {
// 处理接收到的消息
System.out.println("Received message: " + message);
}
}
这个例子展示了如何创建一个消息监听器来接收RocketMQ的消息。@RocketMQMessageListener
注解指定了要监听的topic和消费者组。实现了RocketMQListener
接口,并在onMessage
方法中编写了接收消息后的处理逻辑。这个例子需要在具体的Spring Cloud Alibaba集成的RocketMQ环境中运行。
评论已关闭