点击查看【bilibili】
安装 RocketMQ
git clone https://github.com/pig-mesh/rocketmq-docker-compose
vim rocketmq-docker-compose/data/broker/broker.conf
./run.sh
代码整合
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>2.2.1</version>
</dependency>
rocketmq:
name-server: 192.168.0.12:9876
producer:
group: test-group
@Slf4j
@Service
@RocketMQMessageListener(topic = "test-topic-1", consumerGroup = "test-group")
public static class MyConsumer1 implements RocketMQListener<String> {
public void onMessage(String message) {
log.info("received message: {}", message);
}
}
@SpringBootTest
class DemoApplicationTests {
@Autowired
private RocketMQTemplate rocketMQTemplate;
@Test
void contextLoads() {
rocketMQTemplate.convertAndSend("test-topic-1", "Hello, World!");
}
}
❤ 问题咨询