public override void ExecuteCmdlet() { SubscriptionAttributes subAttributes = new SubscriptionAttributes(); NamespaceAttributes getNamespaceLoc = Client.GetNamespace(ResourceGroup, NamespaceName); subAttributes.Location = getNamespaceLoc.Location; subAttributes.Name = SubscriptionName; if (AutoDeleteOnIdle != null) { subAttributes.AutoDeleteOnIdle = AutoDeleteOnIdle; } if (DeadLetteringOnFilterEvaluationExceptions != null) { subAttributes.DeadLetteringOnFilterEvaluationExceptions = DeadLetteringOnFilterEvaluationExceptions; } if (DeadLetteringOnMessageExpiration != null) { subAttributes.DeadLetteringOnMessageExpiration = DeadLetteringOnMessageExpiration; } if (EnableBatchedOperations != null) { subAttributes.EnableBatchedOperations = EnableBatchedOperations; } if (DeadLetteringOnMessageExpiration != null) { subAttributes.DeadLetteringOnMessageExpiration = DeadLetteringOnMessageExpiration; } if (IsReadOnly != null) { subAttributes.IsReadOnly = IsReadOnly; } if (LockDuration != null) { subAttributes.LockDuration = LockDuration; } if (MaxDeliveryCount != null) { subAttributes.MaxDeliveryCount = MaxDeliveryCount; } if (RequiresSession != null) { subAttributes.RequiresSession = RequiresSession; } if (ShouldProcess(target: SubscriptionName, action: string.Format("Create a new Subscription:{0} for Topic:{1} of Namsespae:{2}", SubscriptionName, TopicName, NamespaceName))) { WriteObject(Client.CreateUpdateSubscription(ResourceGroup, NamespaceName, TopicName, subAttributes.Name, subAttributes)); } }
public Subscription(Model.Subscription item) { SubscriptionType = item.SubscriptionType.ToString(); if (item.ObjectDefinitionID != null && item.PropertyDefinitionID != null) { Model.ObjectDefinition objectDefinition = DataAccessFactory.ObjectDefinitions.GetLookups().GetObjectDefinition(item.ObjectDefinitionID); if (objectDefinition != null) { Model.PropertyDefinition propertyDefinition = objectDefinition.GetProperty(item.PropertyDefinitionID); if (propertyDefinition != null) { Property = propertyDefinition.SerialisationName; } } } Url = item.Url; AcceptContentType = item.AcceptContentType; if (item.NotificationParameters != null) { Attributes = new SubscriptionAttributes(); Attributes.Pmin = item.NotificationParameters.MinimumPeriod; Attributes.Pmax = item.NotificationParameters.MaximumPeriod; Attributes.Step = item.NotificationParameters.Step; Attributes.LessThan = item.NotificationParameters.LessThan; Attributes.GreaterThan = item.NotificationParameters.GreaterThan; } }
public Subscription(Model.Subscription item) { SubscriptionType = item.SubscriptionType.ToString(); if (item.ObjectDefinitionID != null && item.PropertyDefinitionID != null) { Model.ObjectDefinition objectDefinition = DataAccessFactory.ObjectDefinitions.GetLookups().GetObjectDefinition(item.ObjectDefinitionID); if (objectDefinition != null) { Model.PropertyDefinition propertyDefinition = objectDefinition.GetProperty(item.PropertyDefinitionID); if (propertyDefinition != null) Property = propertyDefinition.SerialisationName; } } Url = item.Url; AcceptContentType = item.AcceptContentType; if (item.NotificationParameters != null) { Attributes = new SubscriptionAttributes(); Attributes.Pmin = item.NotificationParameters.MinimumPeriod; Attributes.Pmax = item.NotificationParameters.MaximumPeriod; Attributes.Step = item.NotificationParameters.Step; Attributes.LessThan = item.NotificationParameters.LessThan; Attributes.GreaterThan = item.NotificationParameters.GreaterThan; } }
public override void ExecuteCmdlet() { SubscriptionAttributes subAttributes = new SubscriptionAttributes(); NamespaceAttributes getNamespaceLoc = Client.GetNamespace(ResourceGroupName, Namespace); subAttributes.Name = Name; if (AutoDeleteOnIdle != null) { subAttributes.AutoDeleteOnIdle = AutoDeleteOnIdle; } if (DefaultMessageTimeToLive != null) { subAttributes.DefaultMessageTimeToLive = DefaultMessageTimeToLive; } if (LockDuration != null) { subAttributes.LockDuration = LockDuration; } if (DeadLetteringOnMessageExpiration != null) { subAttributes.DeadLetteringOnMessageExpiration = DeadLetteringOnMessageExpiration; } if (EnableBatchedOperations != null) { subAttributes.EnableBatchedOperations = EnableBatchedOperations; } if (DeadLetteringOnMessageExpiration != null) { subAttributes.DeadLetteringOnMessageExpiration = DeadLetteringOnMessageExpiration; } if (MaxDeliveryCount != null) { subAttributes.MaxDeliveryCount = MaxDeliveryCount; } if (RequiresSession != null) { subAttributes.RequiresSession = RequiresSession; } if (ShouldProcess(target: Name, action: string.Format(Resources.CreateSubscription, Name, Topic, Namespace))) { WriteObject(Client.CreateUpdateSubscription(ResourceGroupName, Namespace, Topic, Name, subAttributes)); } }
public override void ExecuteCmdlet() { if (!string.IsNullOrEmpty(Name)) { SubscriptionAttributes subscriptionAttributes = Client.GetSubscription(ResourceGroupName, Namespace, Topic, Name); WriteObject(subscriptionAttributes); } else { IEnumerable <SubscriptionAttributes> subscriptionAttributes = Client.ListSubscriptions(ResourceGroupName, Namespace, Topic); WriteObject(subscriptionAttributes, true); } }
public override void ExecuteCmdlet() { SubscriptionAttributes subscriptionAttributes = new SubscriptionAttributes(); if (InputObject != null) { subscriptionAttributes = InputObject; } else { // subscriptionAttributes = SubscriptionObj; } if (ShouldProcess(target: subscriptionAttributes.Name, action: string.Format(Resources.UpdateSubscription, subscriptionAttributes.Name, Namespace))) { WriteObject(Client.CreateUpdateSubscription(ResourceGroupName, Namespace, Topic, subscriptionAttributes.Name, subscriptionAttributes)); } }
public override void ExecuteCmdlet() { SubscriptionAttributes subscriptionAttributes = null; if (SubscriptionObj != null) { subscriptionAttributes = SubscriptionObj; } else { // subscriptionAttributes = SubscriptionObj; } if (ShouldProcess(target: subscriptionAttributes.Name, action: string.Format("Update Subscription:{0} of Topic:{1}", subscriptionAttributes.Name, NamespaceName))) { WriteObject(Client.CreateUpdateSubscription(ResourceGroup, NamespaceName, TopicName, subscriptionAttributes.Name, subscriptionAttributes)); } }
public SubscriptionAttributes CreateUpdateSubscription(string resourceGroupName, string namespaceName, string topicName, string subscriptionName, SubscriptionAttributes subscription) { var parameters = new SubscriptionCreateOrUpdateParameters() { AutoDeleteOnIdle = subscription.AutoDeleteOnIdle, DefaultMessageTimeToLive = subscription.DefaultMessageTimeToLive, DeadLetteringOnFilterEvaluationExceptions = subscription.DeadLetteringOnFilterEvaluationExceptions, DeadLetteringOnMessageExpiration = subscription.DeadLetteringOnMessageExpiration, EnableBatchedOperations = subscription.EnableBatchedOperations, EntityAvailabilityStatus = subscription.EntityAvailabilityStatus, IsReadOnly = subscription.IsReadOnly, LockDuration = subscription.LockDuration, MaxDeliveryCount = subscription.MaxDeliveryCount, RequiresSession = subscription.RequiresSession, Status = subscription.Status, Location = subscription.Location }; var response = Client.Subscriptions.CreateOrUpdate(resourceGroupName, namespaceName, topicName, subscriptionName, parameters); return(new SubscriptionAttributes(response)); }
static void Main(string[] args) { var config = Newtonsoft.Json.JsonConvert.DeserializeObject <ConfigModel>(File.ReadAllText(@"E:\MNS.json")); _accessKeyId = config.AccessKeyId; _secretAccessKey = config.AccessKey; _endpoint = config.EndPoint; #region Topic Releated Test Cases IMNS client = new MNSClient(_accessKeyId, _secretAccessKey, _endpoint); /* 1.1. Create queue */ var createTopicRequest = new CreateTopicRequest { TopicName = _topicName }; Topic topic = null; try { client.DeleteTopic(_topicName); topic = client.CreateTopic(createTopicRequest); Console.WriteLine("Create topic successfully, topic name: {0}", topic.TopicName); } catch (Exception ex) { Console.WriteLine("Create topic failed, exception info: " + ex.Message); return; } topic = client.GetNativeTopic(_topicName); try { ListTopicResponse res = client.ListTopic(null, null, 10); Console.WriteLine("List topic successfully, topic name: {0}", _topicName); foreach (String topicUrl in res.TopicUrls) { Console.WriteLine(topicUrl); } if (res.NextMarker != null) { Console.WriteLine("NextMarker: " + res.NextMarker); } } catch (Exception ex) { Console.WriteLine("Delete topic failed, exception info: " + ex.Message); } try { GetTopicAttributesResponse res = topic.GetAttributes(); Console.WriteLine("GetTopicAttributes, topic name: {0}", _topicName); Console.WriteLine(res.Attributes.CreateTime); Console.WriteLine(res.Attributes.LastModifyTime); Console.WriteLine(res.Attributes.MaximumMessageSize); Console.WriteLine(res.Attributes.MessageRetentionPeriod); Console.WriteLine(res.Attributes.LoggingEnabled); } catch (Exception ex) { Console.WriteLine("GetTopicAttributes failed, exception info: " + ex.Message); } try { TopicAttributes attributes = new TopicAttributes() { MaximumMessageSize = 2048 }; topic.SetAttributes(attributes); Console.WriteLine("SetTopicAttributes succeed, topic name: {0}", _topicName); } catch (Exception ex) { Console.WriteLine("SetTopicAttributes failed, exception info: " + ex.Message + ex.GetType().Name); } try { SubscribeResponse res = topic.Subscribe(_subscriptionName, "http://XXXX"); Console.WriteLine("Subscribe, subscriptionUrl: {0}", res.SubscriptionUrl); } catch (Exception ex) { Console.WriteLine("Subscribe failed, exception info: " + ex.Message); } try { GetSubscriptionAttributeResponse res = topic.GetSubscriptionAttribute(_subscriptionName); Console.WriteLine("GetSubscriptionAttributeResponse, subs name: {0}", _subscriptionName); Console.WriteLine(res.Attributes.CreateTime); Console.WriteLine(res.Attributes.LastModifyTime); Console.WriteLine(res.Attributes.TopicName); Console.WriteLine(res.Attributes.TopicOwner); Console.WriteLine(res.Attributes.EndPoint); Console.WriteLine(res.Attributes.Strategy); } catch (Exception ex) { Console.WriteLine("GetSubscriptionAttribute failed, exception info: " + ex.Message); } try { SubscriptionAttributes attributes = new SubscriptionAttributes() { Strategy = SubscriptionAttributes.NotifyStrategy.EXPONENTIAL_DECAY_RETRY }; topic.SetSubscriptionAttribute(_subscriptionName, attributes); Console.WriteLine("SetSubscriptionAttribute succeed, topic name: {0}", _topicName); } catch (Exception ex) { Console.WriteLine("SetSubscriptionAttribute failed, exception info: " + ex.Message + ex.GetType().Name); } try { GetSubscriptionAttributeResponse res = topic.GetSubscriptionAttribute(_subscriptionName); Console.WriteLine("GetSubscriptionAttributeResponse, subs name: {0}", _subscriptionName); Console.WriteLine(res.Attributes.CreateTime); Console.WriteLine(res.Attributes.LastModifyTime); Console.WriteLine(res.Attributes.TopicName); Console.WriteLine(res.Attributes.TopicOwner); Console.WriteLine(res.Attributes.EndPoint); Console.WriteLine(res.Attributes.Strategy); Console.WriteLine(res.Attributes.ContentFormat); } catch (Exception ex) { Console.WriteLine("GetSubscriptionAttribute failed, exception info: " + ex.Message); } try { ListSubscriptionResponse res = topic.ListSubscription(""); Console.WriteLine("ListSubscription successfully, topic name: {0}", _topicName); foreach (String subscriptionUrl in res.SubscriptionUrls) { Console.WriteLine(subscriptionUrl); } if (res.NextMarker != null) { Console.WriteLine("NextMarker: " + res.NextMarker); } } catch (Exception ex) { Console.WriteLine("ListSubscription failed, exception info: " + ex.Message); } try { var response = topic.PublishMessage("message here </asdas\">"); Console.WriteLine("PublishMessage succeed! " + response.MessageId); } catch (Exception ex) { Console.WriteLine("PublishMessage failed, exception info: " + ex.Message); Console.WriteLine(ex.StackTrace); } try { topic.Unsubscribe(_subscriptionName); Console.WriteLine("Unsubscribe succeed!"); } catch (Exception ex) { Console.WriteLine("Subscribe failed, exception info: " + ex.Message); Console.WriteLine(ex.StackTrace); } //// PUBLISH MESSAGE for SMS //try //{ // var res = topic.Subscribe(_subscriptionName + "batchsms", topic.GenerateBatchSmsEndpoint()); // Console.WriteLine(res.SubscriptionUrl); // PublishMessageRequest request = new PublishMessageRequest(); // MessageAttributes messageAttributes = new MessageAttributes(); // BatchSmsAttributes batchSmsAttributes = new BatchSmsAttributes(); // batchSmsAttributes.FreeSignName = "陈舟锋"; // batchSmsAttributes.TemplateCode = "SMS_15535414"; // Dictionary<string, string> param = new Dictionary<string, string>(); // param.Add("name", "CSharpBatch"); // batchSmsAttributes.AddReceiver("13735576932", param); // messageAttributes.BatchSmsAttributes = batchSmsAttributes; // request.MessageAttributes = messageAttributes; // request.MessageBody = "</asdas\">"; // PublishMessageResponse resp = topic.PublishMessage(request); // Console.WriteLine(resp.MessageId); // // check sms // System.Threading.Thread.Sleep(3000); //} //catch (Exception ex) //{ // Console.WriteLine("Subscribe failed, exception info: " + ex.Message); //} //// PUBLISH MESSAGE for SMS //try //{ // var res = topic.Subscribe(_subscriptionName + "singlesms", topic.GenerateSmsEndpoint()); // Console.WriteLine(res.SubscriptionUrl); // PublishMessageRequest request = new PublishMessageRequest(); // MessageAttributes messageAttributes = new MessageAttributes(); // SmsAttributes smsAttributes = new SmsAttributes(); // smsAttributes.FreeSignName = "陈舟锋"; // smsAttributes.TemplateCode = "SMS_15535414"; // Dictionary<string, string> param = new Dictionary<string, string>(); // param.Add("name", "CSharpSingle"); // smsAttributes.Receiver = "13735576932"; // smsAttributes.SmsParams = param; // messageAttributes.SmsAttributes = smsAttributes; // request.MessageAttributes = messageAttributes; // request.MessageBody = "</asdas\">"; // PublishMessageResponse resp = topic.PublishMessage(request); // Console.WriteLine(resp.MessageId); // // check sms // System.Threading.Thread.Sleep(3000); //} //catch (Exception ex) //{ // Console.WriteLine("Subscribe failed, exception info: " + ex.Message); //} //// PUBLISH MESSAGE TO QUEUE AND MAIL //string queueName = "TestQueueNameHere"; //try //{ // var queue = client.CreateQueue(queueName); // var res = topic.Subscribe(_subscriptionName, topic.GenerateMailEndpoint("*****@*****.**")); // // res = topic.Subscribe(_subscriptionName + "2", topic.GenerateQueueEndpoint(queueName)); // res = topic.Subscribe(new SubscribeRequest(_subscriptionName + "2", topic.GenerateQueueEndpoint(queueName), "TAG", SubscriptionAttributes.NotifyStrategy.BACKOFF_RETRY, SubscriptionAttributes.NotifyContentFormat.JSON)); // PublishMessageRequest request = new PublishMessageRequest(); // MessageAttributes messageAttributes = new MessageAttributes(); // MailAttributes mailAttributes = new MailAttributes(); // mailAttributes.AccountName = "*****@*****.**"; // mailAttributes.Subject = "TestMail C#"; // mailAttributes.IsHtml = false; // mailAttributes.ReplyToAddress = false; // mailAttributes.AddressType = 0; // messageAttributes.MailAttributes = mailAttributes; // request.MessageAttributes = messageAttributes; // request.MessageTag = "TAG"; // request.MessageBody = "message here2222 </asdas\">"; // topic.PublishMessage(request); // var resp = queue.ReceiveMessage(30); // Console.WriteLine(resp.Message.Body); // // check mailbox // System.Threading.Thread.Sleep(3000); //} //catch (Exception ex) //{ // Console.WriteLine("Subscribe failed, exception info: " + ex.Message); //} //try //{ // client.DeleteQueue(queueName); //} //catch (Exception ex) //{ // Console.WriteLine("Delete queue failed, exception info: " + ex.Message); //} try { client.DeleteTopic(_topicName); Console.WriteLine("Delete topic successfully, topic name: {0}", _topicName); } catch (Exception ex) { Console.WriteLine("Delete topic failed, exception info: " + ex.Message); } #endregion Console.ReadKey(); }
/// <inheritdoc/> public SetSubscriptionAttributeResponse SetSubscriptionAttribute(string subscriptionName, SubscriptionAttributes attributes) { return(SetSubscriptionAttribute(new SetSubscriptionAttributeRequest(subscriptionName, attributes))); }
public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context) { XmlTextReader reader = new XmlTextReader(context.ResponseStream); SubscriptionAttributes attributes = new SubscriptionAttributes(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.LocalName) { case MNSConstants.XML_ELEMENT_TOPIC_NAME: reader.Read(); attributes.TopicName = reader.Value; break; case MNSConstants.XML_ELEMENT_CREATE_TIME: reader.Read(); attributes.CreateTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value) * 1000); break; case MNSConstants.XML_ELEMENT_LAST_MODIFY_TIME: reader.Read(); attributes.LastModifyTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(long.Parse(reader.Value) * 1000); break; case MNSConstants.XML_ELEMENT_TOPIC_OWNER: reader.Read(); attributes.TopicOwner = reader.Value; break; case MNSConstants.XML_ELEMENT_SUBSCRIPTION_NAME: reader.Read(); attributes.SubscriptionName = reader.Value; break; case MNSConstants.XML_ELEMENT_ENDPOINT: reader.Read(); attributes.EndPoint = reader.Value; break; case MNSConstants.XML_ELEMENT_NOTIFY_STRATEGY: reader.Read(); string strategyStr = reader.Value; attributes.Strategy = (SubscriptionAttributes.NotifyStrategy) Enum.Parse(typeof(SubscriptionAttributes.NotifyStrategy), strategyStr.ToUpper()); break; case MNSConstants.XML_ELEMENT_NOTIFY_CONTENT_FORMAT: reader.Read(); string contentFormatStr = reader.Value; attributes.ContentFormat = (SubscriptionAttributes.NotifyContentFormat) Enum.Parse(typeof(SubscriptionAttributes.NotifyContentFormat), contentFormatStr.ToUpper()); break; } break; } } reader.Close(); return(new GetSubscriptionAttributeResponse() { Attributes = attributes }); }
public async Task <SetSubscriptionAttributeResponse> SetSubscriptionAttributeAsync(string subscriptionName, SubscriptionAttributes attributes) { return(await SetSubscriptionAttributeAsync(new SetSubscriptionAttributeRequest(subscriptionName, attributes)).ConfigureAwait(false)); }
/// <inheritdoc/> public SetSubscriptionAttributeResponse SetSubscriptionAttribute(string subscriptionName, SubscriptionAttributes attributes) { return(AggregateExceptionExtract.Extract(() => { return SetSubscriptionAttributeAsync(subscriptionName, attributes).Result; })); }
public SubscriptionAttributes CreateUpdateSubscription(string resourceGroupName, string namespaceName, string topicName, string subscriptionName, SubscriptionAttributes subscription) { var parameters = new SBSubscription(); if (subscription.AutoDeleteOnIdle != null) { parameters.AutoDeleteOnIdle = (TimeSpan?)AzureServiceBusCmdletBase.ParseTimespan(subscription.AutoDeleteOnIdle); } if (subscription.DefaultMessageTimeToLive != null) { parameters.DefaultMessageTimeToLive = (TimeSpan?)AzureServiceBusCmdletBase.ParseTimespan(subscription.DefaultMessageTimeToLive); } if (subscription.LockDuration != null) { parameters.LockDuration = (TimeSpan?)AzureServiceBusCmdletBase.ParseTimespan(subscription.LockDuration); } if (subscription.DeadLetteringOnMessageExpiration.HasValue) { parameters.DeadLetteringOnMessageExpiration = subscription.DeadLetteringOnMessageExpiration; } if (subscription.EnableBatchedOperations.HasValue) { parameters.EnableBatchedOperations = subscription.EnableBatchedOperations; } if (subscription.MaxDeliveryCount.HasValue) { parameters.MaxDeliveryCount = subscription.MaxDeliveryCount; } if (subscription.RequiresSession.HasValue) { parameters.RequiresSession = subscription.RequiresSession; } if (subscription.Status.HasValue) { parameters.Status = subscription.Status; } var response = Client.Subscriptions.CreateOrUpdate(resourceGroupName, namespaceName, topicName, subscriptionName, parameters); return(new SubscriptionAttributes(response)); }
/// <summary> /// Instantiates SetSubscriptionAttributeRequest with the parameterized properties /// </summary> /// <param name="attributes">The subscription attributes to set.</param> public SetSubscriptionAttributeRequest(string subscriptionName, SubscriptionAttributes attributes) { _subscriptionName = subscriptionName; _attributes = attributes; }