internal CreateTopicResponse CreateTopic(CreateTopicRequest request) { var marshaller = new CreateTopicRequestMarshaller(); var unmarshaller = CreateTopicResponseUnmarshaller.Instance; return(Invoke <CreateTopicRequest, CreateTopicResponse>(request, marshaller, unmarshaller)); }
public void FindTopic() { // create new topic var name = "dotnetsdk" + DateTime.Now.Ticks; var createTopicRequest = new CreateTopicRequest { Name = name }; var createTopicResult = Client.CreateTopic(createTopicRequest); var topicArn = createTopicResult.TopicArn; try { // find the topic by name var foundTopic = Client.FindTopic(name); // verify that the topic was fund Assert.IsNotNull(foundTopic); } finally { // delete the topic var deleteTopicRequest = new DeleteTopicRequest { TopicArn = topicArn }; Client.DeleteTopic(deleteTopicRequest); } }
public void SNSSubscriptionPost() { var snsClient = new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.USEast2); string nombreTopic = "nuevo Tema"; var nuevoTopic = new CreateTopicRequest { Name = nombreTopic, Attributes = new Dictionary <string, string> () { { accessKey, accessSecret } } }; // var a = snsClient.CreateTopicAsync // String topicArn = "arn:aws:sns:us-west-2:433048134094:mytopic"; // Console.WriteLine("va bien"); // String msg = "If you receive this message, publishing a message to an Amazon SNS topic works."; // PublishRequest publishRequest = new PublishRequest(topicArn, msg); // Console.WriteLine("va bien 2"); // var publishResponse = await snsClient.PublishAsync(publishRequest); // Console.WriteLine("va bien 3"); // // Print the MessageId of the published message. // Console.WriteLine ("MessageId: " + publishResponse.MessageId); // await snsClient.PublishAsync(publishRequest); }
public ICollection <string> FetchTopics(IEnumerable <string> topicNames) { if (topicNames == null) { throw new ArgumentNullException(nameof(topicNames)); } Connect(initSNS: true, initSQS: false); var topicArns = new List <string>(); foreach (var topic in topicNames) { var createTopicRequest = new CreateTopicRequest(topic.NormalizeForAws()); var createTopicResponse = _snsClient.CreateTopicAsync(createTopicRequest).GetAwaiter().GetResult(); topicArns.Add(createTopicResponse.TopicArn); } GenerateSqsAccessPolicyAsync(topicArns) .GetAwaiter().GetResult(); return(topicArns); }
public string createPlatformApplicationAndAttachToTopic(string deviceToken, string username) { if (deviceToken == null || username == null) { throw new ArgumentException("Passing null device token or username"); } var topicRequest = new CreateTopicRequest { Name = username + "_myTopic" }; var topicResponse = snsClient.CreateTopic(topicRequest); var createPlatformApplicationRequest = new CreatePlatformApplicationRequest { // Platform Credential is the SERVER API KEY FOR GCM Attributes = new Dictionary <string, string>() { { "PlatformCredential", API_KEY }, { "EventEndpointCreated", topicResponse.TopicArn } }, Name = username + "_platform", Platform = "GCM" }; var createPlatformResponse = snsClient.CreatePlatformApplication(createPlatformApplicationRequest); string platformApplicationArn = createPlatformResponse.PlatformApplicationArn; var request1 = new CreatePlatformEndpointRequest { CustomUserData = "", PlatformApplicationArn = platformApplicationArn, Token = deviceToken }; // Getting the endpoint result // It contains Endpoint ARN that needs to be subscripted to a topic var createPlatformEndpointResult = snsClient.CreatePlatformEndpoint(request1); try { snsClient.Subscribe(new SubscribeRequest { Protocol = "application", TopicArn = topicResponse.TopicArn, Endpoint = createPlatformEndpointResult.EndpointArn }); } catch (Exception e) { Console.WriteLine(e.Message.ToString()); return(null); } return(topicResponse.TopicArn); }
/// <inheritdoc/> public Topic CreateTopic(CreateTopicRequest request) { return(AggregateExceptionExtract.Extract(() => { return CreateTopicAsync(request).Result; })); }
public async Task <ActionResult <Topic> > AddTopic([FromRoute] string id, [FromBody] CreateTopicRequest input) { try { var configurations = new Dictionary <string, object>(); if (input.Configurations != null) { foreach (var(key, value) in input.Configurations) { var jsonElement = (JsonElement)value; configurations[key] = JsonObjectTools.GetValueFromJsonElement(jsonElement); } } input.Configurations = configurations; var returnTopic = await _KafkaServiceClient.CreateTopic( capabilityId : id, createTopicRequest : input ); return(new ActionResult <Topic>(returnTopic)); } catch (UnauthorizedException) { return(Unauthorized()); } catch (RecoverableUpstreamException ex) { return(StatusCode((int)ex.HttpStatusCode, ex.Message)); } }
public async Task <string> CreateTopic(string topicName) { var request = new CreateTopicRequest(topicName); var response = await _sns.CreateTopicAsync(request); return(response.TopicArn); }
public void Subscribe(IEnumerable <string> topics) { if (topics == null) { throw new ArgumentNullException(nameof(topics)); } Connect(initSNS: true, initSQS: false); var topicArns = new List <string>(); foreach (var topic in topics) { var createTopicRequest = new CreateTopicRequest(topic.NormalizeForAws()); var createTopicResponse = _snsClient.CreateTopicAsync(createTopicRequest).GetAwaiter().GetResult(); topicArns.Add(createTopicResponse.TopicArn); } Connect(initSNS: false, initSQS: true); _snsClient.SubscribeQueueToTopicsAsync(topicArns, _sqsClient, _queueUrl) .GetAwaiter().GetResult(); }
public async Task <ActionResult <bool> > CreateTopicAsync(Guid clientId, [Required] string token, [Required] CreateTopicRequest request, [Required][Range(0, int.MaxValue)] int timeout) { await _service.CreateTopicAsync(clientId, token, request, TimeSpan.FromMilliseconds(timeout)); return(CreatedAtAction(nameof(GetMetadata), new { clientId, token, request.Topic, timeout }, true)); }
public async Task <string> CreateTopic(Topology.Entities.Topic topic) { lock (_lock) { if (_topicArns.TryGetValue(topic.EntityName, out var result)) { return(result); } } var request = new CreateTopicRequest(topic.EntityName) { Attributes = topic.TopicAttributes.ToDictionary(x => x.Key, x => x.Value.ToString()), Tags = topic.TopicTags.Select(x => new Tag { Key = x.Key, Value = x.Value }).ToList() }; TransportLogMessages.CreateTopic(topic.EntityName); var response = await _amazonSns.CreateTopicAsync(request, _cancellationToken).ConfigureAwait(false); EnsureSuccessfulResponse(response); var topicArn = response.TopicArn; lock (_lock) _topicArns[topic.EntityName] = topicArn; await Task.Delay(500, _cancellationToken).ConfigureAwait(false); return(topicArn); }
/// <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); }
/// <summary> /// Initiates the asynchronous execution of the CreateTopic operation. /// <seealso cref="Amazon.SimpleNotificationService.IAmazonSimpleNotificationService"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the CreateTopic operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <CreateTopicResponse> CreateTopicAsync(CreateTopicRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new CreateTopicRequestMarshaller(); var unmarshaller = CreateTopicResponseUnmarshaller.Instance; return(Invoke <IRequest, CreateTopicRequest, CreateTopicResponse>(request, marshaller, unmarshaller, signer, cancellationToken)); }
/// <summary> /// Creates a topic in the specified compartment. For general information about topics, see /// [Managing Topics and Subscriptions](https://docs.cloud.oracle.com/iaas/Content/Notification/Tasks/managingtopicsandsubscriptions.htm). /// <br/> /// For the purposes of access control, you must provide the OCID of the compartment where you want the topic to reside. /// For information about access control and compartments, see [Overview of the IAM Service](https://docs.cloud.oracle.com/Content/Identity/Concepts/overview.htm). /// <br/> /// You must specify a display name for the topic. /// <br/> /// All Oracle Cloud Infrastructure resources, including topics, get an Oracle-assigned, unique ID called an /// Oracle Cloud Identifier (OCID). When you create a resource, you can find its OCID in the response. You can also /// retrieve a resource's OCID by using a List API operation on that resource type, or by viewing the resource in the /// Console. For more information, see [Resource Identifiers](https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm). /// <br/> /// Transactions Per Minute (TPM) per-tenancy limit for this operation: 60. /// /// </summary> /// <param name="request">The request object containing the details to send. Required.</param> /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param> /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param> /// <returns>A response object containing details about the completed operation</returns> /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/ons/CreateTopic.cs.html">here</a> to see an example of how to use CreateTopic API.</example> public async Task <CreateTopicResponse> CreateTopic(CreateTopicRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default) { logger.Trace("Called createTopic"); Uri uri = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/topics".Trim('/'))); HttpMethod method = new HttpMethod("POST"); HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request); requestMessage.Headers.Add("Accept", "application/json"); GenericRetrier retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration); HttpResponseMessage responseMessage; try { if (retryingClient != null) { responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false); } else { responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false); } this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage); return(Converter.FromHttpResponseMessage <CreateTopicResponse>(responseMessage)); } catch (Exception e) { logger.Error($"CreateTopic failed with error: {e.Message}"); throw; } }
private void Ensure() { if (!TopicExists()) { var request = new CreateTopicRequest(); request.Name = TopicName; var response = _snsClient.CreateTopic(request); TopicArn = response.TopicArn; } if (!string.IsNullOrEmpty(SubscriptionName)) { _queueClient = new QueueClient(SubscriptionName); if (!SubscriptionExists()) { var response = _snsClient.Subscribe(new SubscribeRequest { TopicArn = TopicArn, Protocol = "sqs", Endpoint = _queueClient.QueueArn }); _subscriptionArn = response.SubscriptionArn; var attrRequest = new SetSubscriptionAttributesRequest { AttributeName = "RawMessageDelivery", AttributeValue = "true", SubscriptionArn = _subscriptionArn }; _snsClient.SetSubscriptionAttributes(attrRequest); _queueClient.AllowSnsToSendMessages(this); } } }
public void TestPublishAsJson() { // create new topic var name = "dotnetsdk" + DateTime.Now.Ticks; var createTopicRequest = new CreateTopicRequest { Name = name }; var createTopicResult = Client.CreateTopicAsync(createTopicRequest).Result; var topicArn = createTopicResult.TopicArn; try { var pubRequest = new PublishRequest() { TopicArn = topicArn, MessageStructure = "json", Message = "stuff" }; var e = AssertExtensions.ExpectExceptionAsync <InvalidParameterException>(Client.PublishAsync(pubRequest)).Result; Assert.AreEqual("InvalidParameter", e.ErrorCode); Assert.IsTrue(e.Message.Contains("parse")); pubRequest.Message = "{\"default\" : \"Data\"}"; Client.PublishAsync(pubRequest).Wait(); } finally { Client.DeleteTopicAsync(new DeleteTopicRequest { TopicArn = topicArn }).Wait(); } }
async Task <TopicInfo> CreateMissingTopic(Topology.Entities.Topic topic, CancellationToken cancellationToken) { Dictionary <string, string> attributes = topic.TopicAttributes.ToDictionary(x => x.Key, x => x.Value.ToString()); var request = new CreateTopicRequest(topic.EntityName) { Attributes = attributes, Tags = topic.TopicTags.Select(x => new Tag { Key = x.Key, Value = x.Value }).ToList() }; var response = await _client.CreateTopicAsync(request, cancellationToken).ConfigureAwait(false); response.EnsureSuccessfulResponse(); var topicArn = response.TopicArn; var attributesResponse = await _client.GetTopicAttributesAsync(topicArn, cancellationToken).ConfigureAwait(false); attributesResponse.EnsureSuccessfulResponse(); var missingTopic = new TopicInfo(topic.EntityName, topicArn, attributesResponse.Attributes); if (topic.Durable && topic.AutoDelete == false) { lock (_durableTopics) _durableTopics[missingTopic.EntityName] = missingTopic; } return(missingTopic); }
public async Task <Topic> CreateTopicAsync(string topicName) { var request = new CreateTopicRequest { TopicName = topicName }; return(await CreateTopicAsync(request).ConfigureAwait(false)); }
public async Task CreateTopicAsync(Guid clientId, string token, CreateTopicRequest request, TimeSpan timeout) { var wrapper = _provider.GetItem(clientId, token); wrapper.UpdateExpiration(); await wrapper.CreateTopicAsync(request.Topic, request.NumPartitions, request.ReplicationFactor, request.Config, timeout); }
/// <inheritdoc/> public IAsyncResult BeginCreateTopic(CreateTopicRequest request, AsyncCallback callback, object state) { var marshaller = new CreateTopicRequestMarshaller(); var unmarshaller = CreateTopicResponseUnmarshaller.Instance; return(BeginInvoke <CreateTopicRequest>(request, marshaller, unmarshaller, callback, state)); }
/// <inheritdoc/> public Topic CreateTopic(string topicName) { var request = new CreateTopicRequest { TopicName = topicName }; return(CreateTopic(request)); }
public static string CreateTopic(string topicName) { using (var client = new AmazonSimpleNotificationServiceClient(Settings.AccessKey, Settings.Secret)) { var request = new CreateTopicRequest(topicName); return(client.CreateTopic(request).TopicArn); } }
/// <summary> /// Create Topic /// </summary> /// <param name="request">Request</param> public CreateTopicResponse CreateTopic(CreateTopicRequest request) { return(new CreateTopicResponse { TopicId = _messenger.CreateTopic(request.Title, request.Message, request.From, request.To, request.Attachments) }); }
/// <inheritdoc/> public Topic CreateTopic(CreateTopicRequest request) { var marshaller = new CreateTopicRequestMarshaller(); var unmarshaller = CreateTopicResponseUnmarshaller.Instance; var response = Invoke <CreateTopicRequest, CreateTopicResponse>(request, marshaller, unmarshaller); return(new Topic(response.TopicUrl.Substring(response.TopicUrl.LastIndexOf("/") + 1), this)); }
public async Task <Topic> CreateTopicAsync(CreateTopicRequest request) { var marshaller = new CreateTopicRequestMarshaller(); var unmarshaller = CreateTopicResponseUnmarshaller.Instance; var response = await InvokeAsync <CreateTopicRequest, CreateTopicResponse>(request, marshaller, unmarshaller).ConfigureAwait(false); return(new Topic(response.TopicUrl.Substring(response.TopicUrl.LastIndexOf("/") + 1), this)); }
/// <summary> /// Creates a topic. Should only be needed to be used once. /// </summary> /// <param name="topicName"></param> /// <returns></returns> public string CreateTopic(string topicName) { var request = new CreateTopicRequest { Name = topicName }; CreateTopicResponse response = Client.CreateTopic(request); return(response.CreateTopicResult.TopicArn); }
/// <summary> /// Method created to connect and process the Topic/Subscription in the AWS. /// </summary> /// <returns></returns> public void ProcessSubscription() { try { foreach (var topic in _topics) { SqsSnsConfiguration config = GetConnection(topic); MethodInfo method = GetMethod(topic); string topicName = topic.Value.TopicName; string subscriptName = topic.Value.Subscription; //Register Trace on the telemetry WorkBench.Telemetry.TrackTrace($"Topic {topicName} registered"); AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient(config.AwsAccessKeyId, config.AwsSecretAccessKey); var topicRequest = new CreateTopicRequest { Name = topicName }; var topicResponse = snsClient.CreateTopicAsync(topicRequest).Result; var subsRequest = new ListSubscriptionsByTopicRequest { TopicArn = topicResponse.TopicArn }; var subs = snsClient.ListSubscriptionsByTopicAsync(subsRequest).Result.Subscriptions; foreach (Subscription subscription in subs) { try { WorkBench.Telemetry.TrackEvent("Method invoked"); //Use of the Metrics to monitoring the queue's processes, start the metric WorkBench.Telemetry.BeginMetricComputation("MessageProcessed"); //Processing the method defined with queue InvokeProcess(method, Encoding.UTF8.GetBytes(subscription.SubscriptionArn)); WorkBench.Telemetry.ComputeMetric("MessageProcessed", 1); //Finish the monitoring the queue's processes WorkBench.Telemetry.EndMetricComputation("MessageProcessed"); WorkBench.Telemetry.TrackEvent("Method terminated"); WorkBench.Telemetry.TrackEvent("Queue's message completed"); } catch (Exception exRegister) { //Use the class instead of interface because tracking exceptions directly is not supposed to be done outside AMAW (i.e. by the business code) ((LightTelemetry)WorkBench.Telemetry).TrackException(exRegister); } } } } catch (Exception exception) { //Use the class instead of interface because tracking exceptions directly is not supposed to be done outside AMAW (i.e. by the business code) ((LightTelemetry)WorkBench.Telemetry).TrackException(exception); } }
public void CRUDTopics() { // list all topics var allTopics = GetAllTopics(); var currentTopicCount = allTopics.Count; // create new topic var name = "dotnetsdk" + DateTime.Now.Ticks; var createTopicRequest = new CreateTopicRequest { Name = name }; var createTopicResult = Client.CreateTopic(createTopicRequest); var topicArn = createTopicResult.TopicArn; try { // verify there is a new topic allTopics = GetAllTopics(); Assert.AreNotEqual(currentTopicCount, allTopics.Count); // set topic attribute var setTopicAttributesRequest = new SetTopicAttributesRequest { TopicArn = topicArn, AttributeName = "DisplayName", AttributeValue = "Test topic" }; Client.SetTopicAttributes(setTopicAttributesRequest); // verify topic attributes var getTopicAttributesRequest = new GetTopicAttributesRequest { TopicArn = topicArn }; var topicAttributes = Client.GetTopicAttributes(getTopicAttributesRequest).Attributes; Assert.AreEqual(setTopicAttributesRequest.AttributeValue, topicAttributes[setTopicAttributesRequest.AttributeName]); } finally { // delete new topic var deleteTopicRequest = new DeleteTopicRequest { TopicArn = topicArn }; Client.DeleteTopic(deleteTopicRequest); // verify the topic was deleted allTopics = GetAllTopics(); Assert.AreEqual(currentTopicCount, allTopics.Count); } }
private static IDictionary <string, string> ConvertCreateTopic(CreateTopicRequest request) { IDictionary <string, string> dictionary = new Dictionary <string, string>(); dictionary["Action"] = "CreateTopic"; if (request.IsSetName()) { dictionary["Name"] = request.Name; } return(dictionary); }
// snippet-start:[SNS.dotnetv3.CreateSNSTopic] /// <summary> /// Creates a new SNS topic using the supplied topic name. /// </summary> /// <param name="client">The initialized SNS client object used to /// create the new topic.</param> /// <param name="topicName">A string representing the topic name.</param> /// <returns>The Amazon Resource Name (ARN) of the created topic.</returns> public static async Task <string> CreateSNSTopicAsync(IAmazonSimpleNotificationService client, string topicName) { var request = new CreateTopicRequest { Name = topicName, }; var response = await client.CreateTopicAsync(request); return(response.TopicArn); }