How to handle async response in aws sns publish notification
kcs-nareshramoliya opened this issue · 1 comments
kcs-nareshramoliya commented
I have used this for push notification and its working fine but when I publish push notification control goes over and I can't perform database operation after publish call. So how to handle the asynchronous call. Is it possible using Guzzle promise to wait for response?
$sns->publish(array( //Async
'TargetArn' => $userDeviceToken->sns_arn,
'MessageStructure' => 'json',
'Message' => json_encode(array(
'default' => '',
'APNS_SANDBOX' => json_encode(array(
'aps' => array(
'alert' => array(
'body' => $notificationMessage,
'title' => $notificationTitle,
)
),
'badge' => '0',
'sound' => 'default',
'content-available' => '1'
))
))
I want to perform db operation after all the notification publish and sent.
diehlaws commented
Hi @nareshramoliya, thanks for reaching out to us. Messages can be published asynchronously to SNS using the publishAsync()
method, which returns a Guzzle promise for which you can wait()
for a response.
$promise = $sns->publishAsync([
'TargetArn' => $topicArn,
'Message' => $message,
'Subject' => $subject
]);
$promise->wait();