-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from leroy-merlin-br/allow-consume-single-mes…
…sage Allow consume message without using command
- Loading branch information
Showing
53 changed files
with
1,178 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
namespace Metamorphosis; | ||
|
||
use Metamorphosis\Connectors\Consumer\Factory; | ||
use Metamorphosis\Consumers\ConsumerInterface; | ||
use Metamorphosis\Middlewares\Handler\Dispatcher; | ||
use Metamorphosis\Record\ConsumerRecord; | ||
use Metamorphosis\Record\RecordInterface; | ||
use Metamorphosis\TopicHandler\ConfigOptions\Consumer as ConsumerConfigOptions; | ||
|
||
class Consumer | ||
{ | ||
/** | ||
* @var ConsumerInterface | ||
*/ | ||
private $consumer; | ||
|
||
/** | ||
* @var Dispatcher | ||
*/ | ||
private $dispatcher; | ||
|
||
public function __construct(ConsumerConfigManager $configManager, ConsumerConfigOptions $configOptions) | ||
{ | ||
$configManager->set($configOptions->toArray()); | ||
|
||
$this->consumer = Factory::getConsumer(true, $configManager); | ||
$this->dispatcher = new Dispatcher($configManager->middlewares()); | ||
} | ||
|
||
public function consume(): ?RecordInterface | ||
{ | ||
if ($response = $this->consumer->consume()) { | ||
$record = app(ConsumerRecord::class, compact('response')); | ||
|
||
return $this->dispatcher->handle($record); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
<?php | ||
namespace Metamorphosis\Middlewares\Handler; | ||
|
||
use Closure; | ||
use Metamorphosis\Middlewares\MiddlewareInterface; | ||
use Metamorphosis\Record\RecordInterface; | ||
|
||
class Iterator extends AbstractMiddlewareHandler | ||
{ | ||
public function handle(RecordInterface $record): void | ||
public function handle(RecordInterface $record) | ||
{ | ||
$closure = Closure::fromCallable([$this, 'handle']); | ||
$entry = current($this->queue); | ||
$middleware = $entry; | ||
next($this->queue); | ||
|
||
if ($middleware instanceof MiddlewareInterface) { | ||
$middleware->process($record, $this); | ||
return $middleware->process($record, $closure); | ||
} | ||
|
||
return $record; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<?php | ||
namespace Metamorphosis\Middlewares; | ||
|
||
use Metamorphosis\Middlewares\Handler\MiddlewareHandlerInterface; | ||
use Closure; | ||
use Metamorphosis\Record\RecordInterface; | ||
|
||
interface MiddlewareInterface | ||
{ | ||
public function process(RecordInterface $record, MiddlewareHandlerInterface $handler): void; | ||
/** | ||
* @return mixed | ||
*/ | ||
public function process(RecordInterface $record, Closure $next); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace Metamorphosis\TopicHandler\ConfigOptions\Auth; | ||
|
||
interface AuthInterface | ||
{ | ||
public function toArray(): array; | ||
|
||
public function getType(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
namespace Metamorphosis\TopicHandler\ConfigOptions\Auth; | ||
|
||
class EnumType | ||
{ | ||
public const NONE_TYPE = 'none'; | ||
|
||
public const SSL_TYPE = 'ssl'; | ||
|
||
public const SASL_SSL_TYPE = 'sasl_ssl'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
namespace Metamorphosis\TopicHandler\ConfigOptions\Auth; | ||
|
||
class None implements AuthInterface | ||
{ | ||
public function toArray(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return EnumType::NONE_TYPE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
namespace Metamorphosis\TopicHandler\ConfigOptions\Auth; | ||
|
||
class SaslSsl implements AuthInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $mechanisms; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $username; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $password; | ||
|
||
public function __construct(string $mechanisms, string $username, string $password) | ||
{ | ||
$this->mechanisms = $mechanisms; | ||
$this->username = $username; | ||
$this->password = $password; | ||
} | ||
|
||
public function getPassword(): string | ||
{ | ||
return $this->password; | ||
} | ||
|
||
public function getUsername(): string | ||
{ | ||
return $this->username; | ||
} | ||
|
||
public function getMechanisms(): string | ||
{ | ||
return $this->mechanisms; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'type' => $this->getType(), | ||
'mechanisms' => $this->getMechanisms(), | ||
'username' => $this->getUsername(), | ||
'password' => $this->getPassword(), | ||
]; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return EnumType::SASL_SSL_TYPE; | ||
} | ||
} |
Oops, something went wrong.