Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e5e459

Browse files
Using AWS SQS with bref
1 parent 95da5eb commit 5e5e459

File tree

5 files changed

+254
-2
lines changed

5 files changed

+254
-2
lines changed

‎composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"require": {
1111
"php": "^7.2.5",
1212
"bref/bref": "^0.5.29",
13+
"bref/laravel-bridge": "^0.2.0",
1314
"fideloper/proxy": "^4.2",
1415
"fruitcake/laravel-cors": "^1.0",
1516
"guzzlehttp/guzzle": "^6.3",

‎composer.lock‎

Lines changed: 206 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/queue.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
'queue' => env('SQS_QUEUE', 'your-queue-name'),
5858
'suffix' => env('SQS_SUFFIX'),
5959
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
60+
'token' => env('AWS_SESSION_TOKEN'),
6061
],
6162

6263
'redis' => [

‎serverless.yml‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ service: laravel-starter-serverless
22

33
provider:
44
name: aws
5-
region: ap-south-1
5+
region: ap-south-1
66
runtime: provided
77

88
plugins:
@@ -31,3 +31,32 @@ functions:
3131
layers:
3232
- ${bref:layer.php-73} # PHP
3333
- ${bref:layer.console} # The "console" layer
34+
worker:
35+
handler: worker.php
36+
layers:
37+
- ${bref:layer.php-73}
38+
events:
39+
# Declares that our worker is triggered by jobs in SQS
40+
- sqs:
41+
arn: !GetAtt AlertQueue.Arn
42+
# If you create the queue manually, the line above could be:
43+
# arn: 'arn:aws:sqs:us-east-1:1234567890:my_sqs_queue'
44+
# Only 1 item at a time to simplify error handling
45+
batchSize: 1
46+
47+
resources:
48+
Resources:
49+
# The SQS queue
50+
AlertQueue:
51+
Type: AWS::SQS::Queue
52+
Properties:
53+
RedrivePolicy:
54+
maxReceiveCount: 3 # jobs will be retried up to 3 times
55+
# Failed jobs (after the retries) will be moved to the other queue for storage
56+
deadLetterTargetArn: !GetAtt DeadLetterQueue.Arn
57+
58+
# Failed jobs will go into that SQS queue to be stored, until a developer looks at these errors
59+
DeadLetterQueue:
60+
Type: AWS::SQS::Queue
61+
Properties:
62+
MessageRetentionPeriod: 1209600 # maximum retention: 14 days

‎worker.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
11+
$kernel->bootstrap();
12+
13+
return $app->makeWith(LaravelSqsHandler::class, [
14+
'connection' => 'sqs', // this is the Laravel Queue connection
15+
'queue' => getenv('SQS_QUEUE'),
16+
]);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /