作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Amazon AWS SNS 时遇到了一个奇怪的问题:使用 aws-php-sdk
创建订阅和主题时(3.112.7),总是有“幽灵”或“隐形”订阅。
如您所见,这个 订阅存在于“订阅”选项卡中 .但是,当我点击主题链接(这里是 cav_56826
)时,我看不到任何订阅 .
你们已经有类似的问题了吗?这怎么会发生?
这是我的简化代码:
try
{
$arn = "arn:aws:sns:eu-west-1:XXXXXXXXXXXXXXXXX:app/APNS_VOIP_SANDBOX/ios_cav";
$topics = array("allUsers", "cav_56826");
$topicsToSubcribe = array();
foreach ($topics as $topic)
{
$res = $this->snsClient->createTopic(['Name' => $topic]);
if ($res->get('@metadata')['statusCode'] == 200)
{
array_push($topicsToSubcribe, $res->get('TopicArn'));
}
else
{
throw new Exception("An error occured during Amazon SNS createTopic", $res->get('@metadata')['statusCode']);
}
}
$SNSEndPointData = $this->snsClient->createPlatformEndpoint([
'PlatformApplicationArn' => $arn,
'Token' => $token
]);
foreach ($topicsToSubcribe as $topic)
{
$this->snsClient->subscribe([
'Protocol' => "application",
'Endpoint' => $SNSEndPointData->get('EndpointArn'),
'TopicArn' => $topic
]);
}
}
catch (\Exception $e)
{
// Logs some errors
}
最佳答案
使用 PHP 5.6.40
和 AWS SDK PHP 3.122.0
(找到 here )和下面的代码在做了一些更改后,我可以看到预期/正确的行为正在发生。
<?php
require '/usr/src/myapp/aws.phar';
$sdk = new Aws\Sdk([
'region' => 'us-east-1',
'version' => 'latest',
]);
$snsClient = $sdk->createSns();
$token = "XX:YY";
try
{
$arn = "arn:aws:sns:us-east-1:360479286475:app/GCM/test-stackoverflow";
$topics = array("allUsers", "cav_56826");
$topicsToSubcribe = array();
foreach ($topics as $topic)
{
$res = $snsClient->createTopic(['Name' => $topic]);
if ($res->get('@metadata')['statusCode'] == 200)
{
array_push($topicsToSubcribe, $res->get('TopicArn'));
}
else
{
throw new Exception("An error occured during Amazon SNS createTopic", $res->get('@metadata')['statusCode']);
}
}
$SNSEndPointData = $snsClient->createPlatformEndpoint([
'PlatformApplicationArn' => $arn,
'Token' => $token
]);
foreach ($topicsToSubcribe as $topic)
{
$snsClient->subscribe([
'Protocol' => "application",
'Endpoint' => $SNSEndPointData->get('EndpointArn'),
'TopicArn' => $topic
]);
}
}
catch (\Exception $e)
{
// Logs some errors
}
?>
关于amazon-web-services - AWS SNS : Why is my "ghost" subscription not showing in Topic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57576738/
我是一名优秀的程序员,十分优秀!