gpt4 book ai didi

amazon-web-services - AWS SNS : Why is my "ghost" subscription not showing in Topic

转载 作者:行者123 更新时间:2023-12-04 21:02:20 25 4
gpt4 key购买 nike

我在使用 Amazon AWS SNS 时遇到了一个奇怪的问题:使用 aws-php-sdk 创建订阅和主题时(3.112.7),总是有“幽灵”或“隐形”订阅。

AWS Console screenshot

如您所见,这个 订阅存在于“订阅”选项卡中 .但是,当我点击主题链接(这里是 cav_56826)时,我看不到任何订阅 .

AWS Topic screenshot

你们已经有类似的问题了吗?这怎么会发生?

这是我的简化代码:

  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
}

?>

所有订阅:
all subscriptions

“所有用户”订阅:
enter image description here

希望这可以帮助。

关于amazon-web-services - AWS SNS : Why is my "ghost" subscription not showing in Topic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57576738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com