3hh/laravel-4-sqs-sns-subscription-queue

A simple Laravel 4.2 service provider which adds a new queue connector to handle SNS subscription queues.

v3.0.1 2019-03-01 02:03 UTC

README

Purpose

This package was forked from joblocal/laravel-sqs-sns-subscription-queue to provide compatibility with Laravel 4.2 and PHP 5.5

Introduction

An Illuminate/Queue queue connector extension for use in Laravel and Lumen.

Using this connector allows SQS messages originating from a SNS subscription to be worked on with Illuminate\Queue\Jobs\SqsJob.

Understand that this package will not handle publishing to SNS, please use the AWS SDK to publish an event to SNS.

Requirements

  • PHP 5.3
  • Laravel 4.2

Usage

Add the LaravelSqsSnsSubscriptionQueue ServiceProvider to your application.

Laravel

Registering Service Providers in Laravel

'providers' => [
    // ...
    ThreeHH\LaravelSqsSnsSubscriptionQueue\SqsSnsServiceProvider::class,
],

Lumen

Registering Service Providers in Lumen

$app->register(ThreeHH\LaravelSqsSnsSubscriptionQueue\SqsSnsServiceProvider::class);

Configuration

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

'connections' => [
  'sqs-sns' => [
    'driver' => 'sqs-sns',
    'key'    => getenv('AWS_ACCESS_KEY') ?: 'your-public-key',
    'secret' => getenv('AWS_SECRET_ACCESS_KEY') ?: 'your-secret-key',
    'queue'  => getenv('QUEUE_URL') ?: 'your-queue-url',
    'region' => getenv('AWS_DEFAULT_REGION') ?: 'us-east-1',
    'routes' => [
        // you can use the "Subject" field
        'Subject' => 'App\\Jobs\\SnsHandler',
        
        // or the "TopicArn" of your SQS message
        'TopicArn:123' => 'App\\Jobs\\SnsHandler',
        // to specify which job class should handle the job
    ],
  ],
],

Workers

Laravel's Queue command can be passed an argument to specify which connection to sue

php artisan queue:listen sqs-sns

Message transformation

When SNS publishes to SQS queues the received message signature is as follows:

{
  "Type" : "Notification",
  "MessageId" : "63a3f6b6-d533-4a47-aef9-fcf5cf758c76",
  "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
  "Subject" : "Testing publish to subscribed queues",
  "Message" : "Hello world!",
  ...
} 

This package converts that into the structure Laravel expects:

{
  "job": "App\\Jobs\\SnsHandler",
  "data": {
      "Type" : "Notification",
      "MessageId" : "63a3f6b6-d533-4a47-aef9-fcf5cf758c76",
      "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
      "Subject" : "Testing publish to subscribed queues",
      "Message" : "Hello world!",
      ...
  }
}

Installation

The best way to install laravel-sqs-sns-subscription is by using Composer.

To install the most recent version:

composer require 3hh/laravel-4-sqs-sns-subscription-queue