Skip to content

Commit 5c85630

Browse files
committed
Add php artisan vendor:publish --tag=serverless-worker
1 parent 8541a75 commit 5c85630

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

README.md

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,34 +133,12 @@ Note that on AWS Lambda, you do not need to create `AWS_ACCESS_KEY_ID` and `AWS_
133133
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
134134
```
135135
136-
Next, create a `worker.php` file. This is the file that will handle SQS events in AWS Lambda:
136+
Finally, create the `worker.php` file. This is the file that will handle SQS events in AWS Lambda:
137137
138-
```php
139-
<?php declare(strict_types=1);
140-
141-
use Bref\LaravelBridge\Queue\LaravelSqsHandler;
142-
use Illuminate\Foundation\Application;
143-
144-
require __DIR__ . '/vendor/autoload.php';
145-
/** @var Application $app */
146-
$app = require __DIR__ . '/bootstrap/app.php';
147-
148-
/**
149-
* For Lumen, use:
150-
* $app->make(Laravel\Lumen\Console\Kernel::class);
151-
* $app->boot();
152-
*/
153-
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
154-
$kernel->bootstrap();
155-
156-
return $app->makeWith(LaravelSqsHandler::class, [
157-
'connection' => 'sqs', // this is the Laravel Queue connection
158-
'queue' => getenv('SQS_QUEUE'),
159-
]);
138+
```bash
139+
php artisan vendor:publish --tag=serverless-worker
160140
```
161141
162-
You may need to adjust the `connection` and `queue` options above if you customized the configuration in `config/queue.php`. If you are unsure, have a look [at the official Laravel documentation about connections and queues](https://laravel.com/docs/7.x/queues#connections-vs-queues).
163-
164142
That's it! Anytime a job is pushed to the SQS queue, SQS will invoke `worker.php` on AWS Lambda and our job will be executed.
165143
166144
#### Differences and limitations

src/BrefServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function boot(): void
3434
$this->publishes([
3535
__DIR__ . '/../config/serverless.yml' => $this->app->basePath('serverless.yml'),
3636
], 'serverless-config');
37+
$this->publishes([
38+
__DIR__ . '/../worker.php' => $this->app->basePath('worker.php'),
39+
], 'serverless-worker');
3740
}
3841

3942
public function register(): void

worker.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
use Bref\LaravelBridge\Queue\LaravelSqsHandler;
4+
use Illuminate\Foundation\Application;
5+
6+
require __DIR__ . '/vendor/autoload.php';
7+
/** @var Application $app */
8+
$app = require __DIR__ . '/bootstrap/app.php';
9+
10+
/**
11+
* For Lumen, use:
12+
* $app->make(Laravel\Lumen\Console\Kernel::class);
13+
* $app->boot();
14+
*/
15+
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
16+
$kernel->bootstrap();
17+
18+
return $app->makeWith(LaravelSqsHandler::class, [
19+
'connection' => 'sqs', // this is the Laravel Queue connection
20+
'queue' => getenv('SQS_QUEUE'),
21+
]);

0 commit comments

Comments
 (0)