Skip to content

Commit

Permalink
applied fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
otanim committed Oct 30, 2024
1 parent d3e54d1 commit 8fe7bba
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/ServiceBusSQSChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function send($notifiable, Notification $notification): void
/** @var ServiceBusEvent $event */
$event = $notification->toServiceBus($notifiable);
$eventType = $event->getEventType();
$params = $event->getParams();
$message = $event->getParams();
$dontReport = Arr::get($this->config, 'dont_report', []);

if (Arr::get($this->config, 'enabled') == false) {
Expand All @@ -48,7 +48,7 @@ public function send($notifiable, Notification $notification): void
"$eventType service bus notification [disabled]",
[
'event' => $eventType,
'params' => $params,
'params' => $message,
'tags' => [
'service-bus',
],
Expand All @@ -59,18 +59,24 @@ public function send($notifiable, Notification $notification): void
return;
}

$message = $event->getParams();

if (!isset($message['from'], $message['events'][0])) {
Log::error('Invalid payload structure', ['message' => $message]);
Log::error('Invalid message structure', ['message' => $message]);
return;
}

$queueUrl = Arr::get($this->config, 'sqs.queue_url');
$isFifoQueue = strpos($queueUrl, '.fifo') !== false;

$params = [
'QueueUrl' => Arr::get($this->config, 'sqs.queue_url'),
'QueueUrl' => $queueUrl,
'MessageBody' => json_encode($message),
];

if ($isFifoQueue) {
$params['MessageGroupId'] = $message['from'];
$params['MessageDeduplicationId'] = md5(json_encode($message));
}

try {
$response = $this->sqs->sendMessage($params);

Expand All @@ -80,6 +86,8 @@ public function send($notifiable, Notification $notification): void
'message_id' => $response->get('MessageId'),
'event' => $eventName,
]);

$this->hasAttemptedRefresh = false;
} catch (AwsException $exception) {
$code = $exception->getAwsErrorCode();

Expand Down

0 comments on commit 8fe7bba

Please sign in to comment.