thephpleague / tactician-bernard

Tactician integration with the Bernard queueing library
MIT License
19 stars 3 forks source link

Consumer not receiving any commands #29

Open ghost opened 9 years ago

ghost commented 9 years ago

Hi there,

thanks for your package in advance, sounds really great and I have tried to get it working, but I really have no clue hat I am doing wrong here.

I hope you can give a hint here:

$inflector = new HandleClassNameInflector();
$locator = new InMemoryLocator();
$locator->addHandler(new TestCommandHandler(), TestCommand::class);
$nameExtractor = new ClassNameExtractor();
$commandHandlerMiddleware = new CommandHandlerMiddleware($nameExtractor, $locator, $inflector);

$factory = new InMemoryFactory();
$factory->create('commandbus');
$producer = new Producer($factory, new EventDispatcher());
$queueMiddleware = new QueueMiddleware($producer);

$commandBus = new CommandBus([$queueMiddleware]);
//$commandBus = new CommandBus([$commandHandlerMiddleware]);
$commandBus->handle(new TestCommand());

This works like a charm when using CommandHandlerMiddleware, but I need external with QueueMiddleware. I am calling the following with php mypath/commandserver and it starts but never receives any commands added:

$factory = new InMemoryFactory();
$producer = new Producer($factory, new EventDispatcher());
$queueMiddleware = new QueueMiddleware($producer);

$commandBus = new CommandBus([$queueMiddleware]);
$receiver = new League\Tactician\Bernard\Receiver\SeparateBusReceiver($commandBus);

$router = new \Bernard\Router\SimpleRouter([$receiver]);
$router->add('League\Tactician\Bernard\QueueableCommand', $receiver);

$consumer = new \Bernard\Consumer($router, new \Symfony\Component\EventDispatcher\EventDispatcher());
$queue = $factory->create('commandbus');
$consumer->consume($queue);

I tried to debug this adding if ($queue->count() > 0) echo "Received a command." . "\n"; to the consume method in Consumer.php.

The queue is always empty.

sagikazarmark commented 9 years ago

I am not really sure why you configure the producer and the consumer in one script.

What does external mean for you? Are you trying to redispatch Commands to other queues?

ghost commented 9 years ago

That's not defined in the same script. It's defined in two different scripts. "External" means 2 scripts, sorry.

Got the things I need working with the scheduler-plugin of tactician, but I am stil curious about getting it to work with bernard.