|
@@ -21,6 +21,10 @@ class ProducerApplicationTests {
|
|
@Resource
|
|
@Resource
|
|
RabbitTemplate rabbitTemplate;
|
|
RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * work queue 模式发送消息
|
|
|
|
+ * @throws InterruptedException
|
|
|
|
+ */
|
|
@Test
|
|
@Test
|
|
void t1() throws InterruptedException {
|
|
void t1() throws InterruptedException {
|
|
for (int i = 0; i < 100; i++) {
|
|
for (int i = 0; i < 100; i++) {
|
|
@@ -30,24 +34,38 @@ class ProducerApplicationTests {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * fanout 模式发送消息
|
|
|
|
+ */
|
|
@Test
|
|
@Test
|
|
void t2(){
|
|
void t2(){
|
|
rabbitTemplate.convertAndSend(
|
|
rabbitTemplate.convertAndSend(
|
|
"com.lc.fanout.demo", "", "广播模式的消息发送" );
|
|
"com.lc.fanout.demo", "", "广播模式的消息发送" );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * direct 模式发送消息
|
|
|
|
+ */
|
|
@Test
|
|
@Test
|
|
void t3(){
|
|
void t3(){
|
|
rabbitTemplate.convertAndSend(
|
|
rabbitTemplate.convertAndSend(
|
|
"com.lc.direct.demo", "北京", "晴转多云" );
|
|
"com.lc.direct.demo", "北京", "晴转多云" );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * direct 模式发送消息
|
|
|
|
+ */
|
|
@Test
|
|
@Test
|
|
void t4(){
|
|
void t4(){
|
|
rabbitTemplate.convertAndSend(
|
|
rabbitTemplate.convertAndSend(
|
|
"com.lc.direct.demo", "哈尔滨", "多云有雷阵雨" );
|
|
"com.lc.direct.demo", "哈尔滨", "多云有雷阵雨" );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 手工发送消息
|
|
|
|
+ * @throws IOException
|
|
|
|
+ * @throws TimeoutException
|
|
|
|
+ */
|
|
@Test
|
|
@Test
|
|
void sendMsg() throws IOException, TimeoutException {
|
|
void sendMsg() throws IOException, TimeoutException {
|
|
//创建一个连接
|
|
//创建一个连接
|