|
| 1 | +package com.clown.rabbit.admin; |
| 2 | + |
| 3 | +import com.clown.rabbit.user.UserApplication; |
| 4 | +import org.junit.Test; |
| 5 | +import org.junit.runner.RunWith; |
| 6 | +import org.springframework.amqp.core.AmqpAdmin; |
| 7 | +import org.springframework.amqp.core.Binding; |
| 8 | +import org.springframework.amqp.core.DirectExchange; |
| 9 | +import org.springframework.amqp.core.Queue; |
| 10 | +import org.springframework.beans.factory.annotation.Autowired; |
| 11 | +import org.springframework.boot.test.context.SpringBootTest; |
| 12 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 13 | + |
| 14 | +/** |
| 15 | + * @author: Richard·Ackerman |
| 16 | + * @create: 2019/1/22 |
| 17 | + **/ |
| 18 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 19 | +@SpringBootTest(classes = UserApplication.class) |
| 20 | +public class AmqpAdminTest { |
| 21 | + |
| 22 | + @Autowired |
| 23 | + private AmqpAdmin amqpAdmin; |
| 24 | + |
| 25 | + /** |
| 26 | + * 创建交换器 |
| 27 | + */ |
| 28 | + @Test |
| 29 | + public void creatExchange(){ |
| 30 | + DirectExchange exchange = new DirectExchange("admin.exchange"); |
| 31 | + amqpAdmin.declareExchange(exchange); |
| 32 | + System.out.println("创建完成"); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * 创建队列 |
| 37 | + */ |
| 38 | + @Test |
| 39 | + public void creatQueue(){ |
| 40 | + amqpAdmin.declareQueue(new Queue("admin.queue",true)); |
| 41 | + System.out.println("创建完成"); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * 创建Binding |
| 46 | + */ |
| 47 | + @Test |
| 48 | + public void creatBinding(){ |
| 49 | + Binding binding = new Binding("admin.queue", Binding.DestinationType.QUEUE,"admin.exchange","admin.queue",null); |
| 50 | + amqpAdmin.declareBinding(binding); |
| 51 | + System.out.println("创建完成"); |
| 52 | + } |
| 53 | +} |
0 commit comments