コード例 #1
0
        /// <summary>
        /// 获取指定名称的Topic
        /// </summary>
        /// <param name="topicName">Name of the topic.</param>
        /// <returns>Topic.</returns>
        private Topic GetTopic(String topicName)
        {
            if (_topics.ContainsKey(topicName))
            {
                return(_topics[topicName]);
            }

            // 创建消息主题
            Topic topic = null;

            try
            {
                var topicRequest = new CreateTopicRequest {
                    TopicName = topicName
                };
                _client.DeleteTopic(topicName);
                topic = _client.CreateTopic(topicRequest);
                _topics.TryAdd(topicName, topic);
            }
            catch (Exception ex)
            {
                XTrace.WriteLine($"创建消息发送主题 {topicName} 失败。");
                XTrace.WriteException(ex);
            }

            return(topic);
        }
コード例 #2
0
 public void SetUp()
 {
     client = new Aliyun.MNS.MNSClient(_accessKeyId, _secretAccessKey, _endpoint);
     client.CreateTopic("UTTopic");
     try
     {
         client.DeleteTopic("UTTopic2");
     }
     catch (Exception)
     {
         // do nothing
     }
 }
コード例 #3
0
        public void SetUp()
        {
            var config = Newtonsoft.Json.JsonConvert.DeserializeObject <ConfigModel>(File.ReadAllText(@"E:\MNS.json"));

            _accessKeyId     = config.AccessKeyId;
            _secretAccessKey = config.AccessKey;
            _endpoint        = config.EndPoint;
            client           = new MNSClient(_accessKeyId, _secretAccessKey, _endpoint);
            client.CreateTopic("UTTopic");
            try
            {
                client.DeleteTopic("UTTopic2");
            }
            catch (Exception)
            {
                // do nothing
            }
        }
コード例 #4
0
        public void SetAttributesTest()
        {
            Topic topic = client.GetNativeTopic("UTTopic");

            var resp = topic.GetAttributes();
            var originalLoggingEnabled = resp.Attributes.LoggingEnabled;

            TopicAttributes qa = new TopicAttributes();

            topic.SetAttributes(qa);
            resp = topic.GetAttributes();
            Assert.AreEqual(originalLoggingEnabled, resp.Attributes.LoggingEnabled);

            qa = new TopicAttributes()
            {
                LoggingEnabled = false
            };
            topic.SetAttributes(qa);
            resp = topic.GetAttributes();
            Assert.AreEqual(false, resp.Attributes.LoggingEnabled);

            qa = new TopicAttributes();
            topic.SetAttributes(qa);
            resp = topic.GetAttributes();
            Assert.AreEqual(false, resp.Attributes.LoggingEnabled);

            qa = new TopicAttributes()
            {
                LoggingEnabled = true
            };
            topic.SetAttributes(qa);
            resp = topic.GetAttributes();
            Assert.AreEqual(true, resp.Attributes.LoggingEnabled);

            qa = new TopicAttributes();
            topic.SetAttributes(qa);
            resp = topic.GetAttributes();
            Assert.AreEqual(true, resp.Attributes.LoggingEnabled);

            qa = new TopicAttributes()
            {
                LoggingEnabled = false
            };
            topic.SetAttributes(qa);
            resp = topic.GetAttributes();
            Assert.AreEqual(false, resp.Attributes.LoggingEnabled);

            qa = new TopicAttributes()
            {
                LoggingEnabled = true
            };
            var req = new CreateTopicRequest()
            {
                TopicName = "UTTopic2", Attributes = qa
            };
            Topic topic2 = client.CreateTopic(req);

            resp = topic2.GetAttributes();
            Assert.AreEqual(true, resp.Attributes.LoggingEnabled);

            client.DeleteTopic("UTTopic2");

            qa = new TopicAttributes()
            {
                LoggingEnabled = false
            };
            req = new CreateTopicRequest()
            {
                TopicName = "UTTopic2", Attributes = qa
            };
            topic2 = client.CreateTopic(req);
            resp   = topic2.GetAttributes();
            Assert.AreEqual(false, resp.Attributes.LoggingEnabled);
        }