You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Deleted the auto scaling code, this will be its own package
- Removed unneeded abstractions that have equivalents in the
core messenger package
- Refactored layout of code to keep with SF conventions
- Removed old tests
- Added full test suite for new transport
- Added support for delayed messages
- Added support for unique messages
Signed-off-by: RJ Garcia <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+40-16Lines changed: 40 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,14 @@
1
1
# Symfony Messenger Redis Adapter
2
2
3
-
This provides custom Redis Integration with the Symfony Messenger 4.1 system. There already exists an implementation for 4.0, but that is not compatabile with the 4.1 integration (due to Messenger's BC policy).
3
+
This provides custom Redis List Integration with the Symfony Messenger ^4.4 system.
4
4
5
-
It also includes some Enhancers for AutoScaling which provide receivers the ability to properly auto scale requests depending on metrics provided from the Queue.
5
+
The standard redis implementation requires redis 5.0 and utilizes the streams feature, this adapter uses redis lists to power the queue functionality.
6
6
7
7
## Installation
8
8
9
-
Currently, this is best installed by cloning the repo as a submodule then using [path type composer repository](https://getcomposer.org/doc/05-repositories.md#path). This is under the `krak/symfony-messenger-redis`.
10
-
11
-
Until this is in a composer repository, you'll probably need to manually include the bundle in your `config/bundles.php` file like so:
9
+
Install with composer at `krak/symfony-messenger-redis`.
12
10
11
+
If symfony's composer install doesn't automatically register the bundle, you can do so manually:
13
12
14
13
```php
15
14
<?php
@@ -37,14 +36,33 @@ Where `MESSENGER_TRANSPORT_DSN` env is like: `redis://localhost:6379`
37
36
38
37
This will register a transport named `acme_redis` which will properly use the configured Redis transport from this library.
39
38
39
+
### Unique Messages
40
+
41
+
If you ever need to ensure that you a specific job needs to be unique while waiting in the queue, you can use the UniqueStamp.
If you don't pass an identifier to enforce uniqueness, the transport will perform an md5 hash of the message body to create an identifier.
50
+
51
+
Example usage of this stamp:
52
+
53
+
- You dispatch a ProductUpdatedMessage every time a product is saved in one system.
54
+
- You have message handlers that then do some expensive operation based off of that product information
55
+
- In the event a single product gets saved rapidly without effectively changing, it makes no sense to enqueue the same job for that product 100 times
56
+
- Using the unique stamp ensures that if a message is already in the queue for that specific product, don't add in another message since the original message hasn't been processed yet.
57
+
58
+
### Delayed Messages
59
+
60
+
This library supports the DelayStamp provided by the core SF messenger.
61
+
40
62
### Available Options
41
63
42
64
Here are the available options that can be provided to the transport options array or as query parameters:
43
65
44
-
- **blocking_timeout:**
45
-
- *required:* no
46
-
- *default:* 30
47
-
- *description:* The number of seconds for the redis bRpopLpush command to block. **DO NOT** set this value over or around60 seconds or you will experience `redis failed to read` type errors due to a bug in the redis extension.
48
66
- **queue:**
49
67
- *required:* yes
50
68
- *default:* N/A
@@ -60,15 +78,21 @@ However, if for some reason a worker is killed via `SIGKILL` (aka `kill -9`), th
60
78
61
79
It won't hurt anything other than storage to have those `_processing` lists take up space. It also *shouldn't* hurt anything to periodically just wipe out those lists using the `DEL` command. But that would need to be verified that it wouldn't hurt any running workers (which I don't think it will).
62
80
63
-
### ReQueing Failed Messages
81
+
### Using Symfony's Redis Transport at the same time
64
82
65
-
This library makes absolutely no attempt to requeue a message once it's failed. I've found in practice that if a message fails once, it will almost always fail again if re-tried shortly after.
83
+
Both symfony's redis and the krak redis transport register the dsn prefix: `redis://`. In the scenario that you want to support both transports, you'll need to use the `use_krak_redis` option to disable this libraries redis transport.
66
84
67
-
Furthermore, The consequences for having code that can retry after failure mean that all operations must be idempotent, but typically, queued jobs by nature are not that way because they might be integrating with external vendors or payment processing systems that might cause duplicate charges or orders being made (due to an error and then retrying the same message).
68
-
69
-
I imagine in the future we will support better logging of failed messages and the possibility to store failed messages in a db table, but that would be handled via a Receiver decorator and not from the actual redis queing system.
70
-
71
-
It's important to note that currently, this library does not handle any cleaning of the processed queue.
85
+
```yaml
86
+
framework:
87
+
messenger:
88
+
transports:
89
+
krak_redis:
90
+
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
91
+
options: { queue: queue_acme }
92
+
sf_redis:
93
+
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
94
+
options: { use_krak_redis: false } # this allows symfony's redis transport factory to take precedence
0 commit comments