RabbitMQ项目开发实战技巧-非常有用

RabbitMQ消息队列使用测试

在上一篇博文中,已经在Centos7.2上完成消息队列服务器的搭建。这里测试一下是否可以进行正常的消息推送和接收。
因为在项目开发中,使用好单元测试技巧, 可以让你开发效率倍增,而且调试方便,为什么这么讲呢,如果单独依靠启动springboot web服务来调试、开发,等项目一大,你将深有体会,来看看解析吧。

新建一个Spring boot项目,然后进行测试

RabbitMQ项目开发实战技巧-非常有用

代码赏析:

/**
 * @author zhangxiao
 * @qq 490433117
 * @create_date 2021/9/6 9:27
 */
package com.foodie.rabbitmqTest;

import com.foodie.configuration.RabbitmqConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
public class custemTest {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void send() {
        String message = "hello zhangxiazo111";
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_DIRECT_INFORM, RabbitmqConfig.ROUTINGKEY_EMAIL, message);
    }
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
zhaozhangxiao
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!