Ejemplo n.º 1
0
        /// <summary>
        /// 创建一个队列
        /// </summary>
        /// <param name="queueName">队列名称</param>
        /// <param name="meta">        QueueMeta class object </param>
        /// <exception cref="Exception"> </exception>
        /// <exception cref="CMQClientException"> </exception>
        /// <exception cref="CMQServerException"> </exception>
        public virtual void CreateQueue(string queueName, QueueMeta meta)
        {
            SortedDictionary <string, string> param = new SortedDictionary <string, string>();

            if (queueName.Equals(""))
            {
                throw new CMQClientException("Invalid parameter:queueName is empty");
            }
            else
            {
                param["queueName"] = queueName;
            }

            if (meta.MaxMsgHeapNum > 0)
            {
                param["maxMsgHeapNum"] = Convert.ToString(meta.MaxMsgHeapNum);
            }
            if (meta.PollingWaitSeconds > 0)
            {
                param["pollingWaitSeconds"] = Convert.ToString(meta.PollingWaitSeconds);
            }
            if (meta.VisibilityTimeout > 0)
            {
                param["visibilityTimeout"] = Convert.ToString(meta.VisibilityTimeout);
            }
            if (meta.MaxMsgSize > 0)
            {
                param["maxMsgSize"] = Convert.ToString(meta.MaxMsgSize);
            }
            if (meta.MsgRetentionSeconds > 0)
            {
                param["msgRetentionSeconds"] = Convert.ToString(meta.MsgRetentionSeconds);
            }
            if (meta.RewindSeconds > 0)
            {
                param["rewindSeconds"] = Convert.ToString(meta.RewindSeconds);
            }

            string      result  = this.client.Call("CreateQueue", param);
            CreateQueue jsonObj = result.ToObject <CHENBI.CMQ.CreateQueue>();//  JsonConvert.DeserializeObject<Msg.CreateQueue>(result);

            if (jsonObj.Code != 0)
            {
                throw new CMQServerException(jsonObj.Code, jsonObj.Message, jsonObj.RequestId);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string secretId  = "";
            string secretKey = "";
            string endpoint  = "http://cmq-queue-gz.api.qcloud.com";
            string path      = "/v2/index.php";

            Account   account = new Account(secretId, secretKey, endpoint, path);
            QueueMeta meta    = new QueueMeta();

            //创建队列
            account.CreateQueue("q11", meta);
            CMQClient cMQClient = new CMQClient(endpoint, path, secretId, secretKey, "POST");
            Queue     queue     = new Queue("q11", cMQClient);
            var       msgId     = queue.SendMessage("ceshi message");

            //消费一条消息
            var resReceive = queue.ReceiveMessage(30);

            //删除消息
            queue.DeleteMessage(resReceive.ReceiptHandle);

            //获取队列列数
            List <QueueInfo> list = new List <QueueInfo>();
            var count             = account.ListQueue("", 1, 1, list);



            Topic topic = new Topic("topc1", cMQClient);

            topic.PublishMessage("messsssss");



            Subscription subscription = new Subscription("topc1", "subscription1", cMQClient);

            subscription.GetSubscriptionAttributes();

            Console.WriteLine("Hello World!");
        }