-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathProjectingModuleRoutingExtension.php
More file actions
50 lines (44 loc) · 1.97 KB
/
ProjectingModuleRoutingExtension.php
File metadata and controls
50 lines (44 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/*
* licence Apache-2.0
*/
declare(strict_types=1);
namespace Ecotone\Projecting\Config;
use Closure;
use Ecotone\Messaging\Config\Configuration;
use Ecotone\Modelling\Attribute\CommandHandler;
use Ecotone\Modelling\Attribute\EventHandler;
use Ecotone\Modelling\Config\Routing\RoutingEvent;
use Ecotone\Modelling\Config\Routing\RoutingEventHandler;
use Ecotone\Projecting\Attribute\Polling;
use Ecotone\Projecting\Attribute\ProjectionV2;
use Ecotone\Projecting\Attribute\Streaming;
/**
* This routing extension is responsible for changing destination channel to projection triggering channel
*/
class ProjectingModuleRoutingExtension implements RoutingEventHandler
{
/**
* @param Closure(string): string $projectionTriggeringInputChannelFactory
*/
public function __construct(private Closure $projectionTriggeringInputChannelFactory)
{
}
public function handleRoutingEvent(RoutingEvent $event, ?Configuration $messagingConfiguration = null): void
{
$registration = $event->getRegistration();
$isCommandOrEventHandler = $registration->hasAnnotation(CommandHandler::class) || $registration->hasAnnotation(EventHandler::class);
if ($isCommandOrEventHandler && $event->getRegistration()->hasAnnotation(ProjectionV2::class)) {
/** @var ProjectionV2 $projectionAttribute */
$projectionAttribute = $event->getRegistration()->getClassAnnotationsWithType(ProjectionV2::class)[0];
$isPolling = $registration->hasAnnotation(Polling::class);
$isEventStreaming = $registration->hasAnnotation(Streaming::class);
// Event-driven projections (not polling and not event-streaming) should route to projection triggering channel
if (! $isPolling && ! $isEventStreaming) {
$event->setDestinationChannel($this->projectionTriggeringInputChannelFactory->__invoke($projectionAttribute->name));
} else {
$event->cancel();
}
}
}
}