Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient.PublishAsync C# (CSharp) Method

PublishAsync() public method

Initiates the asynchronous execution of the Publish operation.
public PublishAsync ( PublishRequest request, PublishResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
request PublishRequest Container for the necessary parameters to execute the Publish operation on AmazonSimpleNotificationServiceClient.
callback PublishResponse>.AmazonServiceCallback An Action delegate that is invoked when the operation completes.
options AsyncOptions A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.
return void
        public void PublishAsync(PublishRequest request, AmazonServiceCallback<PublishRequest, PublishResponse> callback, AsyncOptions options = null)
        {
            options = options == null?new AsyncOptions():options;
            var marshaller = new PublishRequestMarshaller();
            var unmarshaller = PublishResponseUnmarshaller.Instance;
            Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
            if(callback !=null )
                callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
                    AmazonServiceResult<PublishRequest,PublishResponse> responseObject 
                            = new AmazonServiceResult<PublishRequest,PublishResponse>((PublishRequest)req, (PublishResponse)res, ex , ao.State);    
                        callback(responseObject); 
                };
            BeginInvoke<PublishRequest>(request, marshaller, unmarshaller, options, callbackHelper);
        }

Same methods

AmazonSimpleNotificationServiceClient::PublishAsync ( PublishRequest request, System cancellationToken = default(CancellationToken) ) : Task
AmazonSimpleNotificationServiceClient::PublishAsync ( string topicArn, string message, System cancellationToken = default(CancellationToken) ) : Task
AmazonSimpleNotificationServiceClient::PublishAsync ( string topicArn, string message, string subject, System cancellationToken = default(CancellationToken) ) : Task
AmazonSimpleNotificationServiceClient::PublishAsync ( string topicArn, string message, PublishResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void
AmazonSimpleNotificationServiceClient::PublishAsync ( string topicArn, string message, string subject, PublishResponse>.AmazonServiceCallback callback, AsyncOptions options = null ) : void

Usage Example

Example #1
0
 /// <summary>
 /// returns nothing on error
 /// </summary>
 public string PublishRawMessage(string topicArn, string rawMessage)
 {
     try {
         using (var client = new AmazonSimpleNotificationServiceClient(this.AwsCredentials, this.AwsRegion)) {
             var pr = new PublishRequest();
             pr.TopicArn = topicArn;
             pr.Message  = rawMessage;
             var t = client.PublishAsync(pr);
             t.Wait();
             if (t.IsCompleted && t.Result is object)
             {
                 Trace.TraceInformation($"Outgoing SNS-Message for Topic '{topicArn}' Msg-ID: {t.Result.MessageId}");
                 return(t.Result.MessageId);
             }
             else
             {
                 Trace.TraceError($"Publish SNS-Message for Topic '{topicArn}' FAILED: AWS responded non-success");
                 return(null);
             }
         }
     }
     catch (Exception ex) {
         Trace.TraceError($"Publish SNS-Message for Topic '{topicArn}' EXCEPTION: {ex.Message}");
         return(null);
     }
 }
All Usage Examples Of Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient::PublishAsync
AmazonSimpleNotificationServiceClient