-
Notifications
You must be signed in to change notification settings - Fork 5
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this feature :)
Command/ConsumeTopicCommand.php
Outdated
protected function configure() | ||
{ | ||
$this | ||
->setName('kafka:consume') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should add a namespace for the command name, as it was done here => https://github.com/M6Web/PhpProcessManagerBundle/blob/master/Command/HttpProcessCommand.php#L62
so we could name it m6web:kafka:consume
, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok, I'm going to add bundle namespace
Command/ConsumeTopicCommand.php
Outdated
{ | ||
$this | ||
->setName('kafka:consume') | ||
->setDescription('Consume command to process kafka topic/s') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the /
before s
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
Command/ConsumeTopicCommand.php
Outdated
->setDescription('Consume command to process kafka topic/s') | ||
->addOption('consumer', null,InputOption::VALUE_REQUIRED, 'Consumer name') | ||
->addOption('handler', null,InputOption::VALUE_REQUIRED, 'Handler service name') | ||
->addOption('auto-commit', null,InputOption::VALUE_NONE, 'Auto commit enabled?') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space after null,
(we should set a php-cs-fixer
check in our Travis builds 😱)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, you could maybe use https://styleci.io/
Command/ConsumeTopicCommand.php
Outdated
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$prefixName = $this->getContainer()->getParameter('m6web_kafka.prefix_name'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
register $container = $this->getContainer();
before this line, because this getter is used several times, and we don't know how much time consuming it is compared to a simple variable assignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
Command/ConsumeTopicCommand.php
Outdated
throw new \Exception(sprintf("Message Handler with name '%s' is not defined", $handler)); | ||
} | ||
|
||
$output->writeln('<comment>Waiting for partition assignment... (make take some time when quickly re-joining the group after leaving it.)'.PHP_EOL.'</comment>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(may take ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to add PHP_EOL
since it's already done by writeln
method (except if you really want a double EOL)
source: http://api.symfony.com/3.3/Symfony/Component/Console/Output/OutputInterface.html#method_writeln
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to maintain a double EOL
Command/ConsumeTopicCommand.php
Outdated
$output->writeln('<question>No more messages; will wait for more</question>'); | ||
break; | ||
case RD_KAFKA_RESP_ERR__TIMED_OUT: | ||
$output->writeln('<question>Timed out</question>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<error>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not an error, this appears every time you don't have any messages to consume every X seconds defined in timeout_consuming_queue
$messageHandler->process($message); | ||
break; | ||
case RD_KAFKA_RESP_ERR__PARTITION_EOF: | ||
$output->writeln('<question>No more messages; will wait for more</question>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<info>No more messages. Waiting for more...</info>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this, it's a message about they aren't any messages left
Command/ConsumeTopicCommand.php
Outdated
} | ||
|
||
if($this->shutdown) { | ||
$output->writeln('<question>Shuting down...</question>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<info>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's about color, I don't care if you would prefer to put info :D
@@ -31,11 +32,14 @@ public function load(array $configs, ContainerBuilder $container) | |||
|
|||
$this->loadProducers($container, $config); | |||
$this->loadConsumers($container, $config); | |||
|
|||
$container->setParameter('m6web_kafka.prefix_name', $config['prefix_services_name']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not to sure about this prefix parameter... cc @NastasiaSaby what do you think?
anyway, if this feature is accepted:
I'd name it services_name_prefix
, and you should keep the exact same name for the internal parameter name, so:
$container->setParameter('m6web_kafka.services_name_prefix', $config['services_name_prefix']);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prefix is needed to access here:
$prefixName = $this->getContainer()->getParameter('m6web_kafka.prefix_name');
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
* @param array $config | ||
* @param array $config | ||
* @throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this doc tag is not helpful if there's no throw
statement in the method body, except if you explain in which case this exception is thrown (eg. @throws \MyException If a wrong parameter is used
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @markitosgv for your contribution :)
Command/ConsumeTopicCommand.php
Outdated
} | ||
} | ||
|
||
$output->writeln('<info>End consuming topic gracefully</info>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
successfully?
Handler/MessageHandlerInterface.php
Outdated
*/ | ||
public function process(Message $message); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
End of line
|
||
*Note:* If you aren't using *Symfony Automatic Service Loading*, introduced in Symfony 3.3, you have to put in handler option your service name instead of FQCN. | ||
|
||
This Symfony command provide *signal management* too, handling SIGQUIT, SIGTERM and SIGINT to do a gracefully shutdown, committing last processed message and exiting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provides
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
successfull shutdown?
@@ -53,6 +53,7 @@ Here a configuration example: | |||
|
|||
```yaml | |||
m6_web_kafka: | |||
services_name_prefix: 'custom_prefix' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, we can add a comment to say that we have the possibility to customize the service name by using our own prefix with an optional parameter.
👎 sorry @markitosgv but this will not be merged. We prefer decouple responsibilities and use the https://github.com/M6Web/DaemonBundle to build commands like this and keep this current bundle simple as possible. |
after consulting the maintainers, this will not be merged. Please use the DaemonBundle as mentioned previously. |
Add Symfony command to consume kafka messages, handling signals and providing an interface to implement your own services to consume.