lelivrescolaire/sqs-bundle

Communicate with an SQS queue from inside your symfony 2 application.

dev-aws-extension 2015-01-26 14:14 UTC

This package is not auto-updated.

Last update: 2024-11-09 15:56:34 UTC


README

LeLivreScolaire

SQS Bundle Build Status Coverage Status

Communicate with an SQS queue from inside your symfony 2 application.

This bundle is an extension of lelivrescolaire/AWSBundle.

Installation

$ composer require "lelivrescolaire/sqs-bundle:dev-master"

AppKernel:

public function registerBundles()
{
    $bundles = array(
        new LLS\Bundle\AWSBundle\LLSAWSBundle(),
        new LLS\Bundle\SQSBundle\LLSSQSBundle(),
    );
}

Configuration reference

llsaws:
    identities:
        my_identity:                        # Arbitrary Identity service name
            type: user                      # Identity type name (factory alias)
            fields:                         # Identity fields
                key: '<user AWS key>'
                secret: '<user AWS secret>'
                region: '<region of the SQS queue>'
                endpoint: '<endpoint to plug elasticMQ or other third services; not required>'
    services:
        my_sqs_service:                     # Arbitrary service name
            type: sqs                       # Service Type (factory alias)
            identity: my_identity

llssqs:
    queues:
        my_queue:                   # Arbitrary Queue service name
            service: my_sqs_service # SQS Service name
            name: myQueue           # AWS Queue name

Usage

Given the previous config:

<?php
namespace Acme\Bundle\MyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use LLS\Bundle\SQSBundle\Model\Queue;
use LLS\Bundle\SQSBundle\Model\Message;

class MyController extends Controller
{
    public function myAction()
    {
        $identityAsService = $this->get('llsaws.identities.my_identity');
        $sqsAsService      = $this->get('llsaws.services.my_sqs_service');
        $queueAsService    = $this->get('llssqs.queues.my_queue');

        // Create a queue

        $queue = $sqsAsService->getQueue('myCreatedQueue'); // Instanciate Queue

        $sqsAsService->createQueue($queue); // Remotely create the queue

        var_dump($queue->getUrl()); // Get queue URL

        // Send a message to a queue

        $message = new Message();
        $message->setBody('Hello world!');

        $queueAsService->sendMessage($message);

        // Fetch messages from a queue

        $maxMsg = 10; // Max number of messages to fetch

        $messages = $queueAsService->fetchMessages($maxMsg);

        foreach ($messages as $message) {
            var_dump($message->getBody());
            $queueAsService->delete($message); // Delete message (only works for fetched Messages)
        }
    }
}

Ship Monolog logs to SQS

See here.

Contribution

Feel free to send us Pull Requests and Issues with your fixs and features.

Run test

Unit tests

$ ./bin/atoum

Coding standards

$ ./bin/coke