@@ -80,8 +80,8 @@ public function run($repeat, $timeout = 0)
8080 {
8181 return $ this ->runWorker (function (callable $ canContinue ) use ($ repeat , $ timeout ) {
8282 while ($ canContinue ()) {
83- if ($ payload = $ this ->getPayload ($ timeout )) {
84- list ($ ttr , $ message ) = explode ('; ' , $ payload ['Body ' ], 2 );
83+ if (( $ payload = $ this ->getPayload ($ timeout )) !== null ) {
84+ list ($ ttr , $ message ) = explode ('; ' , base64_decode ( $ payload ['Body ' ]) , 2 );
8585 //reserve it so it is not visible to another worker till ttr
8686 $ this ->reserve ($ payload , $ ttr );
8787
@@ -118,44 +118,6 @@ private function getPayload($timeout = 0)
118118 return null ;
119119 }
120120
121- /**
122- * @return \Aws\Sqs\SqsClient
123- */
124- protected function getClient ()
125- {
126- if ($ this ->_client ) {
127- return $ this ->_client ;
128- }
129-
130- if ($ this ->key !== null && $ this ->secret !== null ) {
131- $ credentials = [
132- 'key ' => $ this ->key ,
133- 'secret ' => $ this ->secret ,
134- ];
135- } else {
136- // use default provider if no key and secret passed
137- //see - http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html#credential-profiles
138- $ credentials = CredentialProvider::defaultProvider ();
139- }
140- $ this ->_client = new SqsClient ([
141- 'credentials ' => $ credentials ,
142- 'region ' => $ this ->region ,
143- 'version ' => $ this ->version ,
144- ]);
145-
146- return $ this ->_client ;
147- }
148-
149- /**
150- * Sets the AWS SQS client instance for the queue.
151- *
152- * @param SqsClient $client AWS SQS client object.
153- */
154- public function setClient (SqsClient $ client )
155- {
156- $ this ->_client = $ client ;
157- }
158-
159121 /**
160122 * Set the visibility to reserve message.
161123 * So that no other worker can see this message.
@@ -224,9 +186,47 @@ protected function pushMessage($message, $ttr, $delay, $priority)
224186 $ model = $ this ->getClient ()->sendMessage ([
225187 'DelaySeconds ' => $ delay ,
226188 'QueueUrl ' => $ this ->url ,
227- 'MessageBody ' => "$ ttr; $ message " ,
189+ 'MessageBody ' => base64_encode ( "$ ttr; $ message " ) ,
228190 ]);
229191
230192 return $ model ['MessageId ' ];
231193 }
194+
195+ /**
196+ * @return \Aws\Sqs\SqsClient
197+ */
198+ protected function getClient ()
199+ {
200+ if ($ this ->_client ) {
201+ return $ this ->_client ;
202+ }
203+
204+ if ($ this ->key !== null && $ this ->secret !== null ) {
205+ $ credentials = [
206+ 'key ' => $ this ->key ,
207+ 'secret ' => $ this ->secret ,
208+ ];
209+ } else {
210+ // use default provider if no key and secret passed
211+ //see - http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/credentials.html#credential-profiles
212+ $ credentials = CredentialProvider::defaultProvider ();
213+ }
214+ $ this ->_client = new SqsClient ([
215+ 'credentials ' => $ credentials ,
216+ 'region ' => $ this ->region ,
217+ 'version ' => $ this ->version ,
218+ ]);
219+
220+ return $ this ->_client ;
221+ }
222+
223+ /**
224+ * Sets the AWS SQS client instance for the queue.
225+ *
226+ * @param SqsClient $client AWS SQS client object.
227+ */
228+ public function setClient (SqsClient $ client )
229+ {
230+ $ this ->_client = $ client ;
231+ }
232232}
0 commit comments