springboot集成rocketmq生产者

SpringBoot整合RocketMQ

下载rocketmq-spring项目

将rocketmq-spring安装到本地仓库

mvn install -Dmaven.skip.test=true

消息生产者

1)添加依赖


    org.springframework.boot
    spring-boot-starter-parent
    2.0.1.RELEASE



    2.0.3



    
        org.apache.rocketmq
        rocketmq-spring-boot-starter
        ${rocketmq-spring-boot-starter-version}
    
    
        org.projectlombok
        lombok
        1.18.6
    
    
        org.springframework.boot
        spring-boot-starter-test
        test
    

2)配置文件

# application.properties
rocketmq.name-server=192.168.25.135:9876;192.168.25.138:9876
rocketmq.producer.group=my-group

3)启动类

@SpringBootApplication
public class MQProducerApplication {
    public static void main(String[] args) {
        SpringApplication.run(MQSpringBootApplication.class);
    }
}

4)测试类

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MQSpringBootApplication.class})
public class ProducerTest {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Test
    public void test1(){
        rocketMQTemplate.convertAndSend("springboot-mq","hello springboot rocketmq");
    }
}

 

你可能感兴趣的:(springboot集成rocketmq生产者)