An open API service indexing awesome lists of open source software.

https://github.com/jeylabs/laravel-sns-sqs-sub-pub

AWS SQS SNS Subscription Queue and publisher
https://github.com/jeylabs/laravel-sns-sqs-sub-pub

aws laravel microservice publisher queue sns sqs subscriber

Last synced: 6 months ago
JSON representation

AWS SQS SNS Subscription Queue and publisher

Awesome Lists containing this project

README

          

# AWS SQS SNS Subscription Queue and publisher

simple extension to the [Illuminate/Queue](https://github.com/illuminate/queue) queue system used in [Laravel](https://laravel.com) and [Lumen](https://lumen.laravel.com/).

Using this connector allows [SQS](https://aws.amazon.com/sqs/) messages originating from a [SNS](https://aws.amazon.com/sns/) subscription to be worked on with Illuminate\Queue\Jobs\SqsJob.

This is especially useful in a miroservice architecture where multiple services subscribe to a common topic with their queues and publish an event to SNS.

## Requirements

- Laravel (tested with version 5.8)
- or Lumen (tested with version 5.8)

## Installation
You can install the package via composer
```bash
composer require jeylabs/laravel-sns-sqs-sub-pub
```
You can optionally publish the config file with:
```bash
php artisan vendor:publish --provider="Jeylabs\SnsSqsPubSub\SnsSqsPubSubServiceProvider" --tag="config"
```
This is the contents of the published config file:

```php
'SampleTopic',
'default_auth_driver' => null,
'map' => [
\App\Jobs\TestSQSJob::class => 'SampleTopic',
],
'published_attributes' => [
'id',
'created_at',
'updated_at'
],
'sns' => [
'key' => env('SNS_SQS_PUB_SUB_AWS_ACCESS_KEY'),
'secret' => env('SNS_SQS_PUB_SUB_AWS_SECRET_ACCESS_KEY'),
'region' => env('SNS_SQS_PUB_SUB_AWS_DEFAULT_REGION', 'us-east-1'),
]
];

```

### Configuration

You'll need to configure the queue connection in your config/queue.php

```php
[
'sns-sqs-sub-pub' => [
'driver' => 'sns-sqs-sub-pub',
'key' => env('SNS_SQS_PUB_SUB_AWS_ACCESS_KEY'),
'secret' => env('SNS_SQS_PUB_SUB_AWS_SECRET_ACCESS_KEY'),
'prefix' => env('SNS_SQS_PUB_SUB_SQS_PREFIX', 'https://sqs.ap-southeast-1.amazonaws.com/your-account-id'),
'queue' => env('SNS_SQS_PUB_SUB_QUEUE_URL', 'your-queue-name'),
'region' => env('SNS_SQS_PUB_SUB_AWS_DEFAULT_REGION', 'us-east-1'),
],
],
];
```
Once the sns-sqs-sub-pub queue connector is configured you can start using it by setting queue driver to 'sns-sqs-sub-pub' in your .env file.

### Job class example

```php
passedInData = $data;
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Log::info(json_encode($this->passedInData));
// Check laravel.log, it should now contain msg string.
}
}

```

### Published event
```php
'SampleTopic'
* ];
*/
}
```

### You'll need to configure .env file
```dotenv
SNS_SQS_PUB_SUB_AWS_SNS_DEFAULT_TOPIC=sampletopic
SNS_SQS_PUB_SUB_AWS_ACCESS_KEY=
SNS_SQS_PUB_SUB_AWS_SECRET_ACCESS_KEY=
SNS_SQS_PUB_SUB_AWS_DEFAULT_REGION=ap-southeast-1
SNS_SQS_PUB_SUB_SQS_PREFIX=https://sqs.ap-southeast-1.amazonaws.com/your-account-id
SNS_SQS_PUB_SUB_QUEUE_URL=https://sqs.ap-southeast-1.amazonaws.com/your-account-id/your-queue-name
```