11
11
use StsGamingGroup \KafkaBundle \Configuration \ConfigurationResolver ;
12
12
use StsGamingGroup \KafkaBundle \Configuration \RawConfiguration ;
13
13
use StsGamingGroup \KafkaBundle \Traits \AddConfigurationsToCommandTrait ;
14
+ use Symfony \Component \Console \Attribute \AsCommand ;
14
15
use Symfony \Component \Console \Command \Command ;
15
16
use Symfony \Component \Console \Input \InputArgument ;
16
17
use Symfony \Component \Console \Input \InputInterface ;
17
18
use Symfony \Component \Console \Input \InputOption ;
18
19
use Symfony \Component \Console \Output \OutputInterface ;
19
20
21
+ #[AsCommand(
22
+ name: 'kafka:consumers:consume ' ,
23
+ description: 'Starts consuming messages from kafka using class implementing ' .ConsumerInterface::class
24
+ )]
20
25
class ConsumeCommand extends Command
21
26
{
22
27
use AddConfigurationsToCommandTrait;
23
28
use DescribeTrait;
24
29
25
- protected static $ defaultName = 'kafka:consumers:consume ' ;
26
-
27
30
private RawConfiguration $ rawConfiguration ;
28
31
private ConsumerProvider $ consumerProvider ;
29
32
private ConsumerClient $ consumerClient ;
@@ -45,14 +48,9 @@ public function __construct(
45
48
46
49
protected function configure (): void
47
50
{
48
- $ this ->setDescription (
49
- sprintf (
50
- 'Starts consuming messages from kafka using class implementing %s. ' ,
51
- ConsumerInterface::class
52
- )
53
- )
54
- ->addArgument ('name ' , InputArgument::REQUIRED , 'Name of the registered consumer. ' )
55
- ->addOption ('describe ' , null , InputOption::VALUE_NONE , 'Describes consumer ' );
51
+ $ this
52
+ ->addArgument (name: 'name ' , mode: InputArgument::REQUIRED , description: 'Name of the registered consumer. ' )
53
+ ->addOption (name: 'describe ' , mode: InputOption::VALUE_NONE , description: 'Describes consumer ' );
56
54
57
55
$ this ->addConfigurations ($ this ->rawConfiguration );
58
56
}
@@ -64,11 +62,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
64
62
if ($ input ->getOption ('describe ' )) {
65
63
$ this ->describe ($ this ->configurationResolver ->resolve ($ consumer , $ input ), $ output , $ consumer );
66
64
67
- return 0 ;
65
+ return self :: SUCCESS ;
68
66
}
69
67
70
68
$ this ->consumerClient ->consume ($ consumer , $ input );
71
69
72
- return 0 ;
70
+ return self :: SUCCESS ;
73
71
}
74
72
}
0 commit comments