doucepei5298 2016-12-19 18:57
浏览 54

如何在SNS发布方法中设置超时?

I'm using the AWS SNS service in my PHP application to send messages to a queue.

If internet connection is down, the application should keep running without writing the messages. But the method that publish messages on the queue has a very long timeout, it makes the application unusable without internet.

I didn't found any place in AWS SDK where I could set a smaller timeout. Is there some way to do this?

Here is an example of the construct of the snsClient object. I've edit the params to use http timeout as @Anthony Neace told, I also try to use request.options connect_timeout as I found here http://docs.aws.amazon.com/aws-sdk-php/v2/guide/configuration.html
I've changed the gateway of my PC to simulate when the internet is down and I got the exception [curl] 28: Resolving timed out after 3000 milliseconds https://sns.sa-east-1.amazonaws.com/

    use Aws\Sns\SnsClient;

    SnsClient::factory([
        'version'     => '...',
        'region'      => '...',
        'credentials' => [
            'key'    => '...',
            'secret' => '...',
        ],
        'http' => [
            'timeout' => 5
        ],
        'request.options' => [
            'connect_timeout' => 5
        ]
    ]);
  • 写回答

1条回答 默认 最新

  • doutou7286 2016-12-19 19:18
    关注

    You can set a timeout in your client's constructor. This will apply to all requests you make with that client, including SnsClient Publish.

    Here's an example from the documentation, modified to use SnsClient:

    use Aws\Sns\SnsClient;
    
    // Timeout after 5 seconds.
    $client = new SnsClient([
        'region'  => 'us-west-2',
        'version' => 'latest',
        'http'    => [
            'timeout' => 5
        ]
    ]);
    

    Further Reading:

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?