https://github.com/emagtechlabs/messenger-mongo-bundle
A Mongo transport for Symfony Messenger
https://github.com/emagtechlabs/messenger-mongo-bundle
messenger-mongo-bundle mongodb queue symfony symfony-messenger transport
Last synced: 6 months ago
JSON representation
A Mongo transport for Symfony Messenger
- Host: GitHub
- URL: https://github.com/emagtechlabs/messenger-mongo-bundle
- Owner: eMAGTechLabs
- License: mit
- Created: 2020-04-23T06:59:44.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-06-16T10:10:51.000Z (9 months ago)
- Last Synced: 2025-08-17T05:52:19.481Z (7 months ago)
- Topics: messenger-mongo-bundle, mongodb, queue, symfony, symfony-messenger, transport
- Language: PHP
- Homepage:
- Size: 62.5 KB
- Stars: 16
- Watchers: 6
- Forks: 12
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Messenger Mongo Bundle
[](https://packagist.org/packages/emag-tech-labs/messenger-mongo-bundle)
[](https://github.com/eMAGTechLabs/messenger-mongo-bundle/actions?query=workflow%3ACI)
[](https://codecov.io/gh/eMAGTechLabs/messenger-mongo-bundle)
[](https://dashboard.stryker-mutator.io/reports/github.com/eMAGTechLabs/messenger-mongo-bundle/master)
This bundle offers a new type of transport for the Symfony Messenger component. While MongoDB is not the best tool to be used as a queue, sometimes it's more convenient to use the tools that your application already uses. For example, if your application already uses MongoDB and you want a persistent storage for the failed messages, I think it's quite handy to use MongoDB as a storage.
### Installation
The recommended way to install the bundle is through Composer:
```
$ composer require emag-tech-labs/messenger-mongo-bundle
```
### Configuration & usage
Take a look [here](https://docs.mongodb.com/php-library/current/reference/method/MongoDBClient__construct/) if you need to find out how to configure the **driverOptions**, **uriOptions** and **dsn** options.
```yaml
framework:
messenger:
transports:
hello_queue:
dsn: mongodb://127.0.0.1:27017
options:
uriOptions: []
driverOptions: []
database: symfony # required
collection: hello_messages # default is "messenger_queue"
queue: hello_queue # default is "default"
redeliver_timeout: 4800 # default is 3600
enable_writeConcern_majority: false # default is true
```
The features described [here](https://symfony.com/doc/current/messenger.html#saving-retrying-failed-messages) can be used also, therefore the following commands are available in order to manually debug the failed messages:
```bash
# see all messages in the failure transport
$ php bin/console messenger:failed:show
# see details about a specific failed message
$ php bin/console messenger:failed:show 20 -vv
# view and retry messages one-by-one
$ php bin/console messenger:failed:retry -vv
# retry specific messages
$ php bin/console messenger:failed:retry 20 30 --force
# remove a message without retrying it
$ php bin/console messenger:failed:remove
# displays the number of queued messages in all transports
$ php bin/console messenger:stats
```
#### Defining an index for the messages collection
The MongoDB collections where messages are stored (default `messenger_queue`) should have the following index defined:
```js
{ available_at: 1 }
```
Without the index, the performance may degrade significantly with a large number of items (100k+) in the queue.
### Submitting bugs and feature requests
If you found a nasty bug or want to propose a new feature, you're welcome to open an issue or create a pull request [here](https://github.com/eMAGTechLabs/messenger-mongo-bundle/issues).