实体类User
用于进行测试,不一定要用数据库,咱们直接就new出一个对象来就行之后
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
private Integer id;
private String username;
}
测试类
在这里由于我们要对三种方式进行测试,因此测试类中的交换机和队列名称要随之变化,那么对于第一种api方式,我们就使用fanout_exchange交换机和fanout_queue_email和fanout_queue_sms来进行api方式。
@SpringBootTest
class Springboot0118ApplicationTests {
@Autowired
private AmqpAdmin amqpAdmin;
@Autowired
private RabbitTemplate rabbitTemplate;
@Test
void contextLoads() {
amqpAdmin.declareExchange(new FanoutExchange("fanout_exchange"));
amqpAdmin.declareQueue(new Queue("fanout_queue_email"));
amqpAdmin.declareQueue(new Queue("fanout_queue_sms"));
amqpAdmin.declareBinding(new Binding("fanout_queue_email",Binding.DestinationType.QUEUE,"fanout_exchange",