提交 a6be6166 编写于 作者: 小傅哥's avatar 小傅哥

小傅哥,feat:Rocket MQ 测试类

上级 336bcdba
package cn.bugstack.xfg.dev.tech.mq;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
@Component
@RocketMQMessageListener(topic = "xfg-mq", consumerGroup = "xfg-group")
public class RocketMQConsumer implements RocketMQListener<String> {
@Override
public void onMessage(String message) {
System.out.println("Received message: " + message);
// 处理消息逻辑
}
}
package cn.bugstack.xfg.dev.tech.mq;
import lombok.Setter;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class RocketMQProducer {
@Setter(onMethod_ = @Autowired)
private RocketMQTemplate rocketmqTemplate;
public void sendMessage(String topic, String message) {
rocketmqTemplate.convertAndSend(topic, message);
}
}
package cn.bugstack.xfg.dev.tech.test;
import cn.bugstack.xfg.dev.tech.mq.RocketMQProducer;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTest {
@Autowired
private RocketMQProducer rocketMQProducer;
@Test
public void test() throws InterruptedException {
while (true) {
rocketMQProducer.sendMessage("xfg-mq", "我是测试消息");
Thread.sleep(3000);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册