Skip to content

Commit f99955f

Browse files
committed
[simple-client] Allow processor instance bind.
1 parent afecde0 commit f99955f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Diff for: pkg/simple-client/SimpleClient.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Enqueue\Dbal\Symfony\DbalTransportFactory;
2020
use Enqueue\Fs\Symfony\FsTransportFactory;
2121
use Enqueue\Psr\PsrContext;
22+
use Enqueue\Psr\PsrProcessor;
2223
use Enqueue\Redis\Symfony\RedisTransportFactory;
2324
use Enqueue\Sqs\Symfony\SqsTransportFactory;
2425
use Enqueue\Stomp\Symfony\RabbitMqStompTransportFactory;
@@ -80,17 +81,25 @@ public function __construct($config)
8081
}
8182

8283
/**
83-
* @param string $topic
84-
* @param string $processorName
85-
* @param callback $processor
84+
* @param string $topic
85+
* @param string $processorName
86+
* @param callable|PsrProcessor $processor
8687
*/
87-
public function bind($topic, $processorName, callable $processor)
88+
public function bind($topic, $processorName, $processor)
8889
{
90+
if (is_callable($processor)) {
91+
$processor = new CallbackProcessor($processor);
92+
}
93+
94+
if (false == $processor instanceof PsrProcessor) {
95+
throw new \LogicException('The processor must be either callable or instance of PsrProcessor');
96+
}
97+
8998
$queueName = $this->getConfig()->getDefaultProcessorQueueName();
9099

91100
$this->getTopicMetaRegistry()->addProcessor($topic, $processorName);
92101
$this->getQueueMetaRegistry()->addProcessor($queueName, $processorName);
93-
$this->getProcessorRegistry()->add($processorName, new CallbackProcessor($processor));
102+
$this->getProcessorRegistry()->add($processorName, $processor);
94103
$this->getRouterProcessor()->add($topic, $queueName, $processorName);
95104
}
96105

0 commit comments

Comments
 (0)