示例#1
0
        public string SendMessage(string msgBody, int delayTime)
        {
            var parameters = this.ClientMeta.CreateGeneralParameters(CMQConstant.SendMessage);

            parameters.Add("queueName", this.QueueName);
            parameters.Add("msgBody", msgBody);
            parameters.Add("delaySeconds", Convert.ToString(delayTime));

            var signature = Sign.Signature(
                parameters,
                this.ClientMeta.Endpoint.Queue,
                this.ClientMeta.Path,
                this.ClientMeta.SecretKey, "POST", this.ClientMeta.SignMethod);

            parameters.Add("Signature", signature);
            var result = this.GenerateRequest()
                         .GetUriJsonContent <GeneralMessageCMQBaseMessage>((http) =>
            {
                return(http.Wrap(parameters.CreateRequestBody()));
            });

            result.IfHasErrorThrowException();
            return(result.MsgId);
        }
示例#2
0
        public void CreateSubscribe(
            string topicName,
            string subscriptionName,
            string queueName,
            SubscriptionMeta meta)
        {
            if (meta.FilterTag != null && meta.FilterTag.Count > 5)
            {
                throw new ClientException("Invalid parameter:Tag number > 5");
            }
            var parameters = this.Meta.CreateGeneralParameters(CMQConstant.Subscribe);

            if (topicName == "")
            {
                throw new ClientException("Invalid parameter: topicName is empty");
            }
            else
            {
                parameters.Add("topicName", topicName);
            }

            if (subscriptionName == "")
            {
                throw new ClientException("Invalid parameter: subscriptionName is empty");
            }
            else
            {
                parameters.Add("subscriptionName", subscriptionName);
            }
            if (meta.Endpoint == "")
            {
                throw new ClientException("Invalid parameter: endpoint is empty");
            }
            else
            {
                parameters.Add("endpoint", meta.Endpoint);
            }

            if (meta.Protocal == "")
            {
                throw new ClientException("Invalid parameter: protocol is empty");
            }
            else
            {
                parameters.Add("protocol", meta.Protocal);
            }

            if (meta.NotifyStrategy == "")
            {
                throw new ClientException("Invalid parameter: notifyStrategy is empty");
            }
            else
            {
                parameters.Add("notifyStrategy", meta.NotifyStrategy);
            }
            if (meta.NotifyContentFormat == "")
            {
                throw new ClientException("Invalid parameter: notifyContentFormat is empty");
            }
            else
            {
                parameters.Add("notifyContentFormat", meta.NotifyContentFormat);
            }

            if (meta.FilterTag != null)
            {
                for (int i = 0; i < meta.FilterTag.Count; ++i)
                {
                    parameters.Add("filterTag." + Convert.ToString(i), meta.FilterTag[i]);
                }
            }

            if (meta.BindingKey != null)
            {
                for (int i = 0; i < meta.BindingKey.Count; ++i)
                {
                    parameters.Add("bindingKey." + Convert.ToString(i), meta.BindingKey[i]);
                }
            }

            var signature = Sign.Signature(
                parameters,
                this.Meta.Endpoint.Topic,
                this.Meta.Path,
                this.Meta.SecretKey,
                "POST",
                this.Meta.SignMethod);

            parameters.Add("Signature", signature);
            var result = string.Concat(this.Meta.Endpoint.Topic, this.Meta.Path)
                         .GetUriJsonContent <GeneralCMQBaseMessage>((http) =>
            {
                return(http.Wrap(parameters.CreateRequestBody()));
            });

            result.IfHasErrorThrowException();
        }