-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RdKafka][Symfony] Kafka always consumes messages from the beginning #570
Comments
Allow either to use assign or subscribe With `assign` it is not possible to use the rebalancing from Kafka. So if no offset is set we use `subscribe` and rebalancing is possible and otherwise if a offset is set we are using assign. @see commit d2fa178 @see php-enqueue#570
@makasim Indeed it is, I just noticed it's on master. Sorry to bother :) I've created a branch with code "backported" (more like copied :) ) to 0.8 branch for your convenience, if you're still going to release 0.8.x versions for a while (since Symfony Messenger component can't work with 0.9 yet as you've mentioned). |
@makasim Sorry had difficulty creating PR due to Github failing ;) |
@Steveb-p Feel free to open PR, the release process is completely automated. I could do it at any moment. |
Allow either to use assign or subscribe With `assign` it is not possible to use the rebalancing from Kafka. So if no offset is set we use `subscribe` and rebalancing is possible and otherwise if a offset is set we are using assign. @see commit d2fa17881fcc2c523b8277f3ba30d1d9caeff667 @see php-enqueue/enqueue-dev#570
I have started to use Symfony Messenger component for inter-application communications and stumbled upon a minor issue with Kafka queue implementation. I'm not sure that core issue is part of either Symfony integration or Enqueue, but I've looked over source code and it all points to wrong offset selection in
enqueue/rdkafka
, so I wanted to ask for advice and / or contribute.For my example, I've created a simple dispatch:
(obviously DisplayNotification is my custom message)
I have created a configuration containing:
After dispatching message a couple of times, I have started consuming them:
However, upon restarting, I have noticed that messages that were supposed to be already handled are popping up again. So I've tried other implementation:
enqueue/fs
- and sure enough messages were handled and removed afterwards.Then, I've tried calling
as Kafka quickstart suggests (just added
--group app_name
). This showed me that offsets are stored on Kafka, just PHP process keeps ignoring it.After some looking, I've noticed that
RdKafkaConsumer
and in particularRdKafkaConsumer::receive
method are responsible for managingoffset
value. I've noticed that__construct
method always sets$this->offset
tonull
, and only other place where offset is actually set is in tests.Then, I've looked into
receive
method itself. Excerpt of current code below:I've replaced
$this->consumer->assign()
call with:which, according to https://arnaud-lb.github.io/php-rdkafka/phpdoc/rdkafka-kafkaconsumer.subscribe.html, should allow library to automatically select partition for this consumer (am I right?).
Am I correct in thinking that this is a bug, not some sort of misconfiguration on my part? I'm not really adept in Kafka yet.
Is this solution acceptable, or will it cause issues I'm not able to see yet?
The text was updated successfully, but these errors were encountered: