Ejemplo n.º 1
0
        public void SetSubscriptionAttributes(SubscriptionMeta meta)
        {
            var parameters = this.ClientMeta.CreateGeneralParameters(CMQConstant.SetSubscriptionAttributes);

            parameters.Add("topicName", this.TopicName);
            parameters.Add("subscriptionName", this.SubscriptionName);
            if (meta.NotifyStrategy != "")
            {
                parameters.Add("notifyStrategy", meta.NotifyStrategy);
            }
            if (meta.NotifyContentFormat != "")
            {
                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.ClientMeta.Endpoint.Topic,
                this.ClientMeta.Path,
                this.ClientMeta.SecretKey, "POST", this.ClientMeta.SignMethod);

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

            result.IfHasErrorThrowException();
        }
Ejemplo n.º 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();
        }