• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Uses Enqueue with Symfony's Messenger component.

Enqueue's transport for Symfony Messenger component

This Symfony Messenger transport allows you to use Enqueue to send and receive your messages from all the supported brokers.

Usage

  1. Install the transport
composer req sroze/messenger-enqueue-transport
  1. Configure the Enqueue bundle as you would normaly do (see Enqueue's Bundle documentation). If you are using the recipes, you should just have to configure the environment variables to configure the default Enqueue transport:
# .env
# ...

###> enqueue/enqueue-bundle ###
ENQUEUE_DSN=amqp://guest:guest@localhost:5672/%2f
###< enqueue/enqueue-bundle ###
  1. Configure Messenger's transport (that we will name amqp) to use Enqueue's default transport:
# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            amqp: enqueue://default
  1. Route the messages that have to go through the message queue:
# config/packages/messenger.yaml
framework:
    messenger:
        # ...

        routing:
            'App\Message\MyMessage': amqp
  1. Consume!
bin/console messenger:consume amqp

Advanced usage

Configure the queue(s) and exchange(s)

In the transport DSN, you can add extra configuration. Here is the common reference DSN (note that the values are just for the example):

enqueue://default
    ?queue[name]=queue_name
    &topic[name]=topic_name
    &deliveryDelay=1800
    &delayStrategy=Enqueue\AmqpTools\RabbitMqDelayPluginDelayStrategy
    &timeToLive=3600
    &receiveTimeout=1000
    &priority=1

Setting Custom Configuration on your Message

Each Enqueue transport (e.g. amqp, redis, etc) has its own message object that can normally be configured by calling setter methods (e.g. $message->setDeliveryDelay(5000)). But in Messenger, you don't have access to these objects directly. Instead, you can set them indirectly via the TransportConfiguration stamp:

use Symfony\Component\Messenger\Envelope;
use Enqueue\MessengerAdapter\EnvelopeItem\TransportConfiguration;

// ...

// create your message like normal
$message = // ...

$transportConfig = (new TransportConfiguration())
    // commmon options have a convenient method
    ->setDeliveryDelay(5000)

    // other transport-specific options are set via metadata
    // example custom option for AmqpMessage
    // each "metadata" will map to a setter on your message
    // will result in setDeliveryMode(AmqpMessage::DELIVERY_MODE_PERSISTENT)
    // being called
    ->addMetadata('deliveryMode', AmqpMessage::DELIVERY_MODE_PERSISTENT)
;

$bus->dispatch((new Envelope($message))->with($transportConfig));

Send a message on a specific topic

You can send a message on a specific topic using TransportConfiguration envelope item with your message:

use Symfony\Component\Messenger\Envelope;
use Enqueue\MessengerAdapter\EnvelopeItem\TransportConfiguration;

// ...

$transportConfig = (new TransportConfiguration())
    ->setTopic('specific-topic')
;

$bus->dispatch((new Envelope($message))->with($transportConfig));

Use AMQP topic exchange

See https://www.rabbitmq.com/tutorials/tutorial-five-php.html

You can use specific topic and queue options to configure your AMQP exchange in topic mode and bind it:

enqueue://default
    ?queue[name]=queue_name
    &queue[bindingKey]=foo.#
    &topic[name]=topic_name
    &topic[type]=topic
    &deliveryDelay=1800
    &delayStrategy=Enqueue\AmqpTools\RabbitMqDelayPluginDelayStrategy
    &timeToLive=3600
    &receiveTimeout=1000
    &priority=1

Here is the way to send a message with a routing key matching this consumer:

$bus->dispatch((new Envelope($message))->with(new TransportConfiguration([
    'topic' => 'topic_name',
    'metadata' => [
        'routingKey' => 'foo.bar'
    ]
])));

Configure custom Kafka message

Here is the way to send a message with with some custom options:

$this->bus->dispatch((new Envelope($message))->with(new TransportConfiguration([
    'topic' => 'test_topic_name',
    'metadata' => [
        'key' => 'foo.bar',
        'partition' => 0,
        'timestamp' => (new \DateTimeImmutable())->getTimestamp(),
        'messageId' => uniqid('kafka_', true),
    ]
])))

More Repositories

1

ngInfiniteScroll

Infinite Scrolling for AngularJS
JavaScript
2,903
star
2

companienv

Companion for .env files
PHP
248
star
3

backbone-upload-manager

An upload manager written using Backbone.js
JavaScript
105
star
4

docker-compose-zsh-plugin

ZSH plugin that display status of project containers
Shell
48
star
5

SRIORestUploadBundle

A symfony bundle to handle multiple upload ways on your REST API.
PHP
46
star
6

live-twig

Adding realtime to Twig templates directly
PHP
34
star
7

PHP-Voronoi-algorithm

Steven Fortune's algorithm in PHP
PHP
31
star
8

api-platform-messenger

Uses API Platform to exposes Commands & Queries dispatched to your Symfony Messenger bus
PHP
31
star
9

ChainOfResponsibility

A light library that simplify the implementation of a chain of responsibility
PHP
24
star
10

kubernetes-client

PHP client for the Kubernetes API
PHP
12
star
11

awesome-venturing

Awesome list of practices, tools and products especially useful in your startup adventure(s).
Ruby
11
star
12

angular-simple-model

Simple model layer for AngularJS applications
JavaScript
9
star
13

kubernetes-vamp-router

Vamp Router integration with Kubernetes
Go
9
star
14

ArgumentResolver

A PHP library to inject arguments to callables based on type hints and arguments' names
PHP
9
star
15

enqueue-bridge

Enqueue bridge for Symfony's Messenger component
8
star
16

fossil

🚧 Fossil is an horizontally scalable event store build on top of a key-value store.
Go
6
star
17

api-platform-messenger-example

API Platform + Symfony Messenger example
PHP
5
star
18

openwhisk-bundle

PHP
5
star
19

tsuru-php-example

PHP Silex application example that run on a Tsuru cluster
PHP
4
star
20

HipacheClient

PHP implementation of an Hipache client
PHP
4
star
21

messenger-workshop

Messenger workshop
PHP
3
star
22

flynn-php-example

Example of PHP application that runs on Flynn
PHP
3
star
23

ngInfiniteScroll-bower

Bower package for ngInfiniteScroll
JavaScript
3
star
24

dockerfiles

My Docker files & composes
Dockerfile
3
star
25

discoverd-client

PHP client of Flynn Discoverd
PHP
3
star
26

message

Symfony Message component split
PHP
2
star
27

backbone.realtime-models

A backbone models and collection realtime synchronization system based on WebSockets (in development)
JavaScript
2
star
28

logstream-client

PHP LogStream client
PHP
2
star
29

SocialShareBundle

Share content on multiple social network at the same time from your Symfony2 application.
PHP
2
star
30

backbone-file-browser

A backbone file browser. (still in development)
JavaScript
2
star
31

live-twig-example

PHP
2
star
32

tsuru-environment

Run Tsuru in a Docker container
ApacheConf
1
star
33

events

PHP
1
star
34

kubernetes-load-balancer-proxifier

Load Balancer proxifier for Kubernetes
Go
1
star
35

PgSQL-parse_url

Librairie parse_url pour PostgreSQL
1
star
36

api-platform-workshop

PHP
1
star
37

miniwiki

MiniWiki created for 24h info 2012
PHP
1
star
38

landing-page

JavaScript
1
star
39

angular-cordova-file

AngularJS module that helps file integration with Apache Cordova
JavaScript
1
star
40

jquery-plugin-vinlinedit

Inline edit with vi style for jQuery
JavaScript
1
star
41

PHP-Gettext-Edit

PHP Gettext files editor
PHP
1
star
42

backbone-defered-view-loader

A backbone view overlay that loads view only when needed
JavaScript
1
star