yangyoupeng

P2PProducer中createQueue方法进行判空操作

...@@ -132,6 +132,8 @@ public class P2PProducer implements ProducerInt<MessageObject,Message>{ ...@@ -132,6 +132,8 @@ public class P2PProducer implements ProducerInt<MessageObject,Message>{
132 } 132 }
133 133
134 public void createQueue(){ 134 public void createQueue(){
135 - queue.create(); 135 + if(!queue.isQueueExist()){
136 + queue.create();
137 + }
136 } 138 }
137 } 139 }
......
...@@ -80,8 +80,8 @@ public class TestCloudPullTopicConsumer { ...@@ -80,8 +80,8 @@ public class TestCloudPullTopicConsumer {
80 //创建一个topic,并且他包含一个testQueue1; 80 //创建一个topic,并且他包含一个testQueue1;
81 CloudPullTopicProducer topicProducer2=builder.buildCloudTopic(topicName,true, testQueue1); 81 CloudPullTopicProducer topicProducer2=builder.buildCloudTopic(topicName,true, testQueue1);
82 82
83 - 83 + topic=builder.buildTopic(topicName);
84 - topicProducer2.send("hellow world1"); 84 + topic.send("hellow world1");
85 85
86 CloudPullTopicConsumer consumer1=builder.buildTopicPullConsumer(topicName, testQueue1); 86 CloudPullTopicConsumer consumer1=builder.buildTopicPullConsumer(topicName, testQueue1);
87 Message msg1=consumer1.popMessage(); 87 Message msg1=consumer1.popMessage();
......
1 +package com.zhaoonline.message.queue;
2 +
3 +import org.junit.Assert;
4 +import org.springframework.beans.factory.annotation.Autowired;
5 +
6 +import com.aliyun.mns.model.Message;
7 +
8 +public class TestUseCloudTopicProducerBuilder {
9 + @Autowired CloudTopicProducerBuilder builder;
10 +
11 + public void createTopic() throws Exception{
12 + String topicName="testTopic1";
13 + String testQueue1 = "testQu1eue";
14 +
15 + TopicProducer topic=builder.buildTopic(topicName);
16 + //发送消息
17 + topic.send("hellow world1");
18 +
19 + CloudPullTopicConsumer consumer1=builder.buildTopicPullConsumer(topicName, testQueue1);
20 + //pop消息
21 + Message msg1=consumer1.popMessage();
22 + Assert.assertEquals("hellow world1", msg1.getMessageBodyAsRawString());
23 + //topic删除方法,会连同topci对应queue都删除
24 + topic.deleteTopic();
25 +
26 + topic.close();
27 + consumer1.close();
28 + }
29 +
30 +}