SQS不能仅在.Net Core中发送qutations消息

时间:2019-02-07 12:56:02

标签: c# amazon-web-services .net-core amazon-sqs

在某些情况下,我需要发送带有正文的邮件:

  

“”

当我尝试使用以下代码进行操作时:

var sqsClient= new AmazonSQSClient(new BasicAWSCredentials("accessKeyId","SecretKey"), new AmazonSQSConfig()
{
 ServiceURL ="https://sqs.eu-west-1.amazonaws.com/"
});
//obj value is "" and provided from user
var result = sqsClient.SendMessageAsync("queueURL", obj.ToString()).Result;

我得到:

  

{Amazon.SQS.AmazonSQSException:请求必须包含参数   邮件正文。 ---> Amazon.Runtime.Internal.HttpErrorResponseException:   类型'Amazon.Runtime.Internal.HttpErrorResponseException'的异常   被扔了。在   Amazon.Runtime.HttpWebRequestMessage.d__20.MoveNext()   在   E:\ JenkinsWorkspaces \ v3-trebuchet-release \ AWSDotNetPublic \ sdk \ src \ Core \ Amazon.Runtime \ Pipeline \ HttpHandler_mobile \ HttpRequestMessageFactory.cs:line   539   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Amazon.Runtime.Internal.HttpHandler 1.<InvokeAsync>d__9 1.MoveNext()   在   E:\ JenkinsWorkspaces \ v3-trebuchet-release \ AWSDotNetPublic \ sdk \ src \ Core \ Amazon.Runtime \ Pipeline \ HttpHandler \ HttpHandler.cs:line   175   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Amazon.Runtime.Internal.Unmarshaller.d__3 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.SQS.Internal.ValidationResponseHandler.<InvokeAsync>d__1 1.MoveNext()   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   中的Amazon.Runtime.Internal.ErrorHandler.d__5 1.MoveNext()
--- End of inner exception stack trace --- at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException exception) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\HttpErrorResponseExceptionHandler.cs:line 60 at Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext executionContext, Exception exception) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\ErrorHandler.cs:line 212 at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5
1.MoveNext()   E:\ JenkinsWorkspaces \ v3-trebuchet-release \ AWSDotNetPublic \ sdk \ src \ Core \ Amazon.Runtime \ Pipeline \ ErrorHandler \ ErrorHandler.cs:line   104   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Amazon.Runtime.Internal.CallbackHandler.d__9 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.EndpointDiscoveryHandler.<InvokeAsync>d__2 1.MoveNext()   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   Amazon.Runtime.Internal.EndpointDiscoveryHandler.d__2 1.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\EndpointDiscoveryHandler.cs:line 79 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7 1.MoveNext()   在   E:\ JenkinsWorkspaces \ v3-trebuchet-release \ AWSDotNetPublic \ sdk \ src \ Core \ Amazon.Runtime \ Pipeline \ Handlers \ CredentialsRetriever.cs:line   98   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Amazon.Runtime.Internal.RetryHandler.d__10 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10 1.MoveNext()   在   E:\ JenkinsWorkspaces \ v3-trebuchet-release \ AWSDotNetPublic \ sdk \ src \ Core \ Amazon.Runtime \ Pipeline \ RetryHandler \ RetryHandler.cs:line   153   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Amazon.Runtime.Internal.CallbackHandler.d__9 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9 1.MoveNext()   ---从上一个引发异常的位置开始的堆栈跟踪-   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务   任务)   Amazon.Runtime.Internal.ErrorCallbackHandler.d__5 1.MoveNext() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\ErrorCallbackHandler.cs:line 58 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1 1.MoveNext()}

但是发送:

  

“”

效果很好!

是否有任何工作环境只能发送

  

“”

1 个答案:

答案 0 :(得分:2)

您说您正在尝试将主体设置为"",但实际上是将主体设置为两个"之间的0字节空字符串。字符串文字实际上并不包含其周围的引号。如果您实际要发送的是空字符串,则在SQS中无效。

  

邮件正文不能为空或为空。

     

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-attributes.html

但是,如果您实际上要发送两个字节的ASCII 0x22 "引号字符,则这些字符必须出现在字符串文字中,并且escaped

var result = sqsClient.SendMessageAsync("queueURL", "\"\"").Result;

(请注意,SQS开发人员指南中的引用来自主要与消息属性相关的页面,但是它的确指向实际的消息正文,而不是消息属性,其内容称为{{1 }},而不是“ body”,并分别提到,并且不支持空值或null。)