88use Illuminate \Queue \Jobs \SqsJob ;
99use Illuminate \Queue \SqsQueue ;
1010use Illuminate \Support \Facades \Config ;
11+ use Illuminate \Support \Facades \Log ;
1112use Illuminate \Support \Str ;
1213use JsonException ;
1314use palPalani \SqsQueueReader \Jobs \DispatcherJob ;
@@ -119,13 +120,11 @@ private function modifySinglePayload(array | string $payload, string $class): ar
119120
120121 $ body = \json_decode ($ payload ['Body ' ], true , 512 , JSON_THROW_ON_ERROR );
121122
122- $ body = [
123+ $ payload [ ' Body ' ] = \json_encode ( [
123124 'uuid ' => (string ) Str::uuid (),
124125 'job ' => $ class . '@handle ' ,
125126 'data ' => $ body ['data ' ] ?? $ body ,
126- ];
127-
128- $ payload ['Body ' ] = \json_encode ($ body , JSON_THROW_ON_ERROR );
127+ ], JSON_THROW_ON_ERROR );
129128
130129 return $ payload ;
131130 }
@@ -148,29 +147,33 @@ private function modifyMultiplePayload(array | string $payload, string $class):
148147 $ receiptHandle = null ;
149148
150149 foreach ($ payload as $ k => $ item ) {
151- $ body [$ k ] = [
152- 'messages ' => \json_decode ($ item ['Body ' ], true , 512 , JSON_THROW_ON_ERROR ),
153- 'attributes ' => $ item ['Attributes ' ],
154- 'batchIds ' => [
155- 'Id ' => $ item ['MessageId ' ],
156- 'ReceiptHandle ' => $ item ['ReceiptHandle ' ],
157- ],
158- ];
159- $ attributes = $ item ['Attributes ' ];
160- $ messageId = $ item ['MessageId ' ];
161- $ receiptHandle = $ item ['ReceiptHandle ' ];
150+ try {
151+ $ body [$ k ] = [
152+ 'messages ' => \json_decode ($ item ['Body ' ], true , 512 , JSON_THROW_ON_ERROR ),
153+ 'attributes ' => $ item ['Attributes ' ],
154+ 'batchIds ' => [
155+ 'Id ' => $ item ['MessageId ' ],
156+ 'ReceiptHandle ' => $ item ['ReceiptHandle ' ],
157+ ],
158+ ];
159+ $ attributes = $ item ['Attributes ' ];
160+ $ messageId = $ item ['MessageId ' ];
161+ $ receiptHandle = $ item ['ReceiptHandle ' ];
162+ } catch (JsonException $ e ) {
163+ Log::warning ('Invalid payload! ' , [$ item ]);
164+
165+ continue ;
166+ }
162167 }
163168
164- $ body = [
165- 'uuid ' => (string ) Str::uuid (),
166- 'job ' => $ class . '@handle ' ,
167- 'data ' => $ body ,
168- ];
169-
170169 return [
171170 'MessageId ' => $ messageId ,
172171 'ReceiptHandle ' => $ receiptHandle ,
173- 'Body ' => \json_encode ($ body , JSON_THROW_ON_ERROR ),
172+ 'Body ' => \json_encode ([
173+ 'uuid ' => (string ) Str::uuid (),
174+ 'job ' => $ class . '@handle ' ,
175+ 'data ' => $ body ,
176+ ], JSON_THROW_ON_ERROR ),
174177 'Attributes ' => $ attributes ,
175178 ];
176179 }
0 commit comments