public function apply(Settings $settings)
 {
     /** @var EnabledPersistence[]|null $enabledPersistences */
     $enabledPersistences = $settings->tryGet(KnownSettingsEnum::ENABLED_PERSISTENCES);
     if (!$enabledPersistences) {
         // TODO tweak the error message (vezi interfetele de care vb in NServicebus)
         // TODO vezi si de SendOnly endpoint cand lamuresti cu sending messages din afara unui handler (fara tranzactie explicita)
         throw new UnexpectedValueException("No persistence has been selected, please select your persistence by calling endpointConfigurator.usePersistence.");
     }
     $enabledPersistences = array_reverse($enabledPersistences);
     $availableStorageTypeValues = array_flip(StorageType::getConstants());
     $supportedStorageTypeValues = [];
     foreach ($enabledPersistences as $enabledPersistence) {
         $currentDefinition = $enabledPersistence->getDefinition();
         $currentDefinition->formalize();
         $selectedStorageType = $enabledPersistence->getSelectedStorageType();
         if ($selectedStorageType && !$currentDefinition->hasSupportFor($selectedStorageType)) {
             $definitionFqcn = get_class($currentDefinition);
             throw new RuntimeException("Definition '{$definitionFqcn}' does not support storage type {$selectedStorageType->getValue()}.");
         }
         $currentSupportedStorageTypeValues = $currentDefinition->getSupportedStorages($selectedStorageType);
         foreach ($currentSupportedStorageTypeValues as $supportedStorageValue) {
             if (isset($availableStorageTypeValues[$supportedStorageValue])) {
                 unset($availableStorageTypeValues[$supportedStorageValue]);
                 $supportedStorageTypeValues[$supportedStorageValue] = $supportedStorageValue;
                 $currentDefinition->applyFor(new StorageType($supportedStorageValue), $settings);
             }
         }
     }
     $settings->set(KnownSettingsEnum::SUPPORTED_STORAGE_TYPE_VALUES, $supportedStorageTypeValues);
 }
Пример #2
0
 /**
  * Method is called if all defined conditions are met and the feature is marked as enabled.
  * Use this method to configure and initialize all required components for the feature like
  * the steps in the pipeline or the instances/factories in the container.
  *
  * @param Settings              $settings
  * @param BuilderInterface      $builder
  * @param PipelineModifications $pipelineModifications
  */
 public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
 {
     $localAddress = $settings->get(KnownSettingsEnum::LOCAL_ADDRESS);
     $builder->defineSingleton(UnicastRouterInterface::class, function () use($localAddress, $builder, $settings) {
         return new UnicastRouter($localAddress, $builder->build(UnicastRoutingTable::class), $settings->get(TransportInfrastructure::class));
     });
     $pipelineModifications->registerStep('UnicastSendRoutingConnector', UnicastSendRoutingConnector::class, function () use($builder) {
         return new UnicastSendRoutingConnector($builder->build(UnicastRouterInterface::class), $builder->build(OutgoingContextFactory::class));
     });
     $pipelineModifications->registerStep('UnicastReplyRoutingConnector', UnicastReplyRoutingConnector::class, function () use($builder) {
         return new UnicastReplyRoutingConnector($builder->build(OutgoingContextFactory::class));
     });
     $pipelineModifications->registerStep('MulticastPublishRoutingConnector', MulticastPublishRoutingConnector::class, function () use($builder) {
         return new MulticastPublishRoutingConnector($builder->build(OutgoingContextFactory::class));
     });
     $canReceive = !$settings->get(KnownSettingsEnum::SEND_ONLY);
     if ($canReceive) {
         $pipelineModifications->registerStep('AttachReplyToAddressPipelineStep', AttachReplyToAddressPipelineStep::class, function () use($localAddress) {
             return new AttachReplyToAddressPipelineStep($localAddress);
         });
         /** @var TransportInfrastructure $transportInfrastructure */
         $transportInfrastructure = $settings->get(TransportInfrastructure::class);
         $subscriptionManagerFactory = $transportInfrastructure->configureSubscriptionInfrastructure();
         $builder->defineSingleton(SubscriptionManagerInterface::class, $subscriptionManagerFactory->getSubscriptionManagerFactory());
         $pipelineModifications->registerStep('SubscribeTerminator', SubscribeTerminator::class, function () use($builder) {
             return new SubscribeTerminator($builder->build(SubscriptionManagerInterface::class));
         });
         $pipelineModifications->registerStep('UnsubscribeTerminator', UnsubscribeTerminator::class, function () use($builder) {
             return new UnsubscribeTerminator($builder->build(SubscriptionManagerInterface::class));
         });
     }
 }
Пример #3
0
 /**
  * Method is called if all defined conditions are met and the feature is marked as enabled.
  * Use this method to configure and initialize all required components for the feature like
  * the steps in the pipeline or the instances/factories in the container.
  *
  * @param Settings              $settings
  * @param BuilderInterface      $builder
  * @param PipelineModifications $pipelineModifications
  */
 public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
 {
     /** @var OutboundTransport $outboundTransport */
     $outboundTransport = $settings->get(OutboundTransport::class);
     $sendInfrastructure = $outboundTransport->configure($settings);
     $builder->defineSingleton(MessageDispatcherInterface::class, $sendInfrastructure->getMessageDispatcherFactory());
 }
 public function install()
 {
     $createQueues = $this->settings->tryGet(KnownSettingsEnum::CREATE_QUEUES);
     if ($createQueues || $createQueues === null) {
         $this->queueCreator->createIfNecessary($this->settings->get(QueueBindings::class));
     }
 }
 /**
  * @param Settings $settings
  *
  * @return bool
  */
 private function isDurableMessagingEnabled(Settings $settings)
 {
     $enabled = $settings->tryGet(KnownSettingsEnum::DURABLE_MESSAGING_ENABLED);
     if ($enabled === null) {
         $enabled = true;
     }
     return $enabled;
 }
Пример #6
0
 /**
  * @param BuilderInterface $builder
  * @param Settings         $settings
  */
 public function installFeatures(BuilderInterface $builder, Settings $settings)
 {
     if (!$settings->tryGet(KnownSettingsEnum::INSTALLERS_ENABLED)) {
         return;
     }
     foreach ($this->features as $feature) {
         if ($feature->isActive()) {
             $feature->install($builder);
         }
     }
 }
Пример #7
0
 /**
  * @return AMQPConnection
  */
 public function createConnection()
 {
     /** @var AMQPConnection $connection */
     $connection = $this->settings->tryGet(RabbitMqKnownSettingsEnum::CONNECTION);
     if (!$connection) {
         $connectionCredentials = $this->settings->tryGet(RabbitMqKnownSettingsEnum::CONNECTION_CREDENTIALS) ?: [];
         $connectionCredentials = array_replace($this->defaultCredentials, $connectionCredentials);
         $connection = new AMQPConnection($connectionCredentials);
     }
     return $connection;
 }
 /**
  * @return Connection
  * @throws DBALException
  */
 public function __invoke()
 {
     $connection = $this->settings->tryGet(Doctrine2KnownSettingsEnum::CONNECTION);
     if ($connection) {
         return $connection;
     }
     $connectionParameters = $this->settings->tryGet(Doctrine2KnownSettingsEnum::CONNECTION_PARAMETERS);
     if (!$connectionParameters) {
         throw new UnexpectedValueException("The Doctrine 2 persistence requires either a connection instance or connection parameters. " . "You can provide them through the persistence configurator.");
     }
     return DriverManager::getConnection($connectionParameters);
 }
Пример #9
0
 /**
  * Method is called if all defined conditions are met and the feature is marked as enabled.
  * Use this method to configure and initialize all required components for the feature like
  * the steps in the pipeline or the instances/factories in the container.
  *
  * @param Settings              $settings
  * @param BuilderInterface      $builder
  * @param PipelineModifications $pipelineModifications
  */
 public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
 {
     $supportedStorageTypes = $settings->get(KnownSettingsEnum::SUPPORTED_STORAGE_TYPE_VALUES);
     if (!in_array(StorageType::OUTBOX, $supportedStorageTypes)) {
         throw new UnexpectedValueException("Selected persistence doesn't have support for outbox storage. " . "Please select another storage or disable the outbox feature using endpointConfigurator.disableFeature.");
     }
     $pipelineModifications->registerStep('OutboxConnector', OutboxConnector::class, function () use($builder) {
         /** @var PipelineFactory $pipelineFactory */
         $pipelineFactory = $builder->build(PipelineFactory::class);
         return new OutboxConnector($pipelineFactory->createStartingWith(DispatchContext::class, $builder->build(PipelineModifications::class)), $builder->build(OutboxStorageInterface::class), $builder->build(IncomingContextFactory::class), $builder->build(OutgoingContextFactory::class), new TransportOperationsConverter(new OutboxTransportOperationFactory()));
     });
 }
Пример #10
0
 /**
  * Method is called if all defined conditions are met and the feature is marked as enabled.
  * Use this method to configure and initialize all required components for the feature like
  * the steps in the pipeline or the instances/factories in the container.
  *
  * @param Settings              $settings
  * @param BuilderInterface      $builder
  * @param PipelineModifications $pipelineModifications
  */
 public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
 {
     /** @var QueueBindings $queueBindings */
     $queueBindings = $settings->get(QueueBindings::class);
     $queueBindings->bindReceiving($settings->get(KnownSettingsEnum::LOCAL_ADDRESS));
     /** @var InboundTransport $inboundTransport */
     $inboundTransport = $settings->get(InboundTransport::class);
     $receiveInfrastructure = $inboundTransport->configure($settings);
     $builder->defineSingleton(MessagePusherInterface::class, $receiveInfrastructure->getMessagePusherFactory());
     $builder->defineSingleton(QueueCreatorInterface::class, $receiveInfrastructure->getQueueCreatorFactory());
     $this->registerInstallTask(function () use($builder, $settings) {
         return new QueueCreatorFeatureInstallTask($builder->build(QueueCreatorInterface::class), $settings);
     });
 }
 /**
  * @return LogicalConnection
  */
 public function __invoke()
 {
     $logicalConnection = $this->settings->tryGet(Doctrine1KnownSettingsEnum::LOGICAL_CONNECTION);
     if ($logicalConnection) {
         return $logicalConnection;
     }
     $dsn = $this->settings->tryGet(Doctrine1KnownSettingsEnum::DSN);
     if (!$dsn) {
         throw new UnexpectedValueException("The Doctrine 1 persistence requires a DSN. You can provide it through the persistence configurator.");
     }
     $manager = $this->settings->tryGet(Doctrine1KnownSettingsEnum::MANAGER);
     if (!$manager) {
         $manager = \Doctrine_Manager::getInstance();
     }
     $connectionName = $this->settings->tryGet(Doctrine1KnownSettingsEnum::CONNECTION_NAME);
     return new LogicalConnection($connectionName, $dsn, $manager);
 }
Пример #12
0
 /**
  * Method is called if all defined conditions are met and the feature is marked as enabled.
  * Use this method to configure and initialize all required components for the feature like
  * the steps in the pipeline or the instances/factories in the container.
  *
  * @param Settings              $settings
  * @param BuilderInterface      $builder
  * @param PipelineModifications $pipelineModifications
  */
 public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
 {
     $errorQueue = $settings->get(KnownSettingsEnum::ERROR_QUEUE);
     /** @var QueueBindings $queueBindings */
     $queueBindings = $settings->get(QueueBindings::class);
     $queueBindings->bindSending($errorQueue);
     $localAddress = $settings->get(KnownSettingsEnum::LOCAL_ADDRESS);
     $builder->defineSingleton(ExceptionToHeadersConverter::class, function () use($builder) {
         return new ExceptionToHeadersConverter($builder->build(ClockInterface::class), $builder->build(DateTimeConverter::class));
     });
     $registration = $pipelineModifications->registerStep('MoveErrorsToErrorQueuePipelineStep', MoveErrorsToErrorQueuePipelineStep::class, function () use($errorQueue, $localAddress, $builder) {
         /** @var PipelineFactory $pipelineFactory */
         $pipelineFactory = $builder->build(PipelineFactory::class);
         return new MoveErrorsToErrorQueuePipelineStep($errorQueue, $localAddress, $pipelineFactory->createStartingWith(DispatchContext::class, $builder->build(PipelineModifications::class)), $builder->build(ExceptionToHeadersConverter::class), $builder->build(OutgoingContextFactory::class));
     });
     $registration->insertBeforeIfExists('FirstLevelRetryPipelineStep');
     $registration->insertBeforeIfExists('SecondLevelRetryPipelineStep');
 }
Пример #13
0
 /**
  * Method is called if all defined conditions are met and the feature is marked as enabled.
  * Use this method to configure and initialize all required components for the feature like
  * the steps in the pipeline or the instances/factories in the container.
  *
  * @param Settings              $settings
  * @param BuilderInterface      $builder
  * @param PipelineModifications $pipelineModifications
  */
 public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
 {
     /** @var SerializationDefinition $definition */
     $definition = $settings->get(SerializationDefinition::class);
     $serializerFactory = $definition->formalize($settings);
     $builder->defineSingleton(MessageSerializerInterface::class, $serializerFactory);
     $builder->defineSingleton(MessageDeserializerResolver::class, function () use($builder) {
         $serializer = $builder->build(MessageSerializerInterface::class);
         return new MessageDeserializerResolver([$serializer], get_class($serializer));
     });
     $builder->defineSingleton(IncomingLogicalMessageFactory::class, new IncomingLogicalMessageFactory());
     $pipelineModifications->registerStep('DeserializeLogicalMessageConnector', DeserializeLogicalMessageConnector::class, function () use($builder) {
         return new DeserializeLogicalMessageConnector($builder->build(MessageDeserializerResolver::class), $builder->build(IncomingLogicalMessageFactory::class), $builder->build(IncomingContextFactory::class));
     });
     $pipelineModifications->registerStep('SerializeMessageConnector', SerializeMessageConnector::class, function () use($builder) {
         return new SerializeMessageConnector($builder->build(MessageSerializerInterface::class), $builder->build(OutgoingContextFactory::class));
     });
 }
Пример #14
0
 /**
  * @return EndpointInstance
  */
 public function start()
 {
     if (!$this->isPrepared) {
         $this->prepare();
     }
     if (!$this->settings->tryGet(KnownSettingsEnum::SEND_ONLY)) {
         /** @var TransportReceiver $transportReceiver */
         $transportReceiver = $this->builder->build(TransportReceiver::class);
         $transportReceiver->start();
     }
     return new EndpointInstance($this->busContext);
 }
 /**
  * Method is called if all defined conditions are met and the feature is marked as enabled.
  * Use this method to configure and initialize all required components for the feature like
  * the steps in the pipeline or the instances/factories in the container.
  *
  * @param Settings              $settings
  * @param BuilderInterface      $builder
  * @param PipelineModifications $pipelineModifications
  */
 public function setup(Settings $settings, BuilderInterface $builder, PipelineModifications $pipelineModifications)
 {
     $builder->defineSingleton(LogicalConnection::class, new LogicalConnectionFactory($settings));
     $builder->defineSingleton(OutboxPersister::class, function () use($builder, $settings) {
         return new OutboxPersister($builder->build(LogicalConnection::class), $settings->get(Doctrine1KnownSettingsEnum::OUTBOX_MESSAGES_TABLE_NAME), $settings->get(Doctrine1KnownSettingsEnum::OUTBOX_ENDPOINTS_TABLE_NAME));
     });
     $builder->defineSingleton(OutboxStorageInterface::class, function () use($builder, $settings) {
         return new Doctrine1OutboxStorage($builder->build(OutboxPersister::class), new OutboxMessageConverter(), $settings->get(Doctrine1KnownSettingsEnum::OUTBOX_ENDPOINT_ID));
     });
     $this->registerStartupTask(function () use($builder, $settings) {
         return new EndpointIdLoaderFeatureStartupTask($builder->build(OutboxPersister::class), $settings, $settings->get(KnownSettingsEnum::ENDPOINT_NAME));
     });
     $this->registerStartupTask(function () use($builder, $settings) {
         return new OutboxCleanerFeatureStartupTask($builder->build(OutboxPersister::class), new \DateTime('now', new \DateTimeZone('UTC')), $settings->tryGet(KnownSettingsEnum::DAYS_TO_KEEP_DEDUPLICATION_DATA));
     });
     $this->registerInstallTask(function () use($builder, $settings) {
         return new OutboxTablesCreatorFeatureInstallTask($builder->build(LogicalConnection::class), new OutboxEndpointSchemaProvider(), new OutboxMessageSchemaProvider(), $settings->get(Doctrine1KnownSettingsEnum::OUTBOX_ENDPOINTS_TABLE_NAME), $settings->get(Doctrine1KnownSettingsEnum::OUTBOX_MESSAGES_TABLE_NAME));
     });
 }
Пример #16
0
 private function registerBaseContainerServices(Container $c)
 {
     $c[Settings::class] = $this->settings;
     $c[MessageHandlerRegistry::class] = $this->messageHandlerRegistry;
     $c[MessageMutatorRegistry::class] = $this->messageMutatorRegistry;
     $c[UnicastRoutingTable::class] = $this->unicastRoutingTable;
     $c[PipelineModifications::class] = $this->pipelineModifications;
     /** @var UuidGenerationDefinition $uuidDefinition */
     $uuidDefinition = $this->settings->get(UuidGenerationDefinition::class);
     $c[UuidGeneratorInterface::class] = $uuidDefinition->formalize($this->settings);
     $c[PipelineFactory::class] = new PipelineFactory($c[BuilderInterface::class], new StepChainBuilderFactory());
     $c[BusOperationsContextFactory::class] = new BusOperationsContextFactory();
     $c[BusOperations::class] = new BusOperations($c[PipelineFactory::class], $c[BusOperationsContextFactory::class], $c[PipelineModifications::class], $c[UuidGeneratorInterface::class]);
     $c[OutgoingOptionsFactory::class] = new OutgoingOptionsFactory();
     $c[BusContext::class] = new BusContext(new PipelineRootStageContext($c[BuilderInterface::class]), $c[BusOperations::class], $c[OutgoingOptionsFactory::class]);
     $c[IncomingContextFactory::class] = function ($c) {
         return new IncomingContextFactory($c[BusOperations::class], $c[OutgoingOptionsFactory::class]);
     };
     $c[OutgoingContextFactory::class] = function () {
         return new OutgoingContextFactory();
     };
     $c[ClockInterface::class] = function () {
         return new SystemClock();
     };
     $c[DateTimeConverter::class] = function () {
         return new DateTimeConverter();
     };
     $c[PushPipe::class] = function ($c) {
         /** @var PipelineFactory $pipelineFactory */
         $pipelineFactory = $c[PipelineFactory::class];
         return new PushPipe(new TransportReceiveContextFactory($c[BuilderInterface::class]), $pipelineFactory->createStartingWith(TransportReceiveContext::class, $c[PipelineModifications::class]));
     };
     $c[PushSettings::class] = function () {
         $errorQueue = $this->settings->tryGet(KnownSettingsEnum::ERROR_QUEUE);
         if (!$errorQueue) {
             throw new UnexpectedValueException("The error queue needs to be set. You can do it using endpointConfigurator.sendFailedMessagesTo.");
         }
         return new PushSettings($this->settings->get(KnownSettingsEnum::LOCAL_ADDRESS), $this->settings->get(KnownSettingsEnum::ERROR_QUEUE), $this->settings->tryGet(KnownSettingsEnum::PURGE_ON_STARTUP) ?: false);
     };
     $c[TransportReceiver::class] = function ($c) {
         return new TransportReceiver($c[MessagePusherInterface::class], $c[PushSettings::class], $c[PushPipe::class]);
     };
 }
Пример #17
0
 /**
  * @param Settings $settings
  *
  * @return TransportSendInfrastructure
  */
 public function configure(Settings $settings)
 {
     /** @var TransportInfrastructure $transportInfrastructure */
     $transportInfrastructure = $settings->get(TransportInfrastructure::class);
     return $transportInfrastructure->configureSendInfrastructure();
 }
 /**
  * @param BusContextInterface $busContext
  */
 public function start(BusContextInterface $busContext)
 {
     $endpointId = $this->outboxPersister->fetchOrGenerateEndpointId($this->endpointName);
     $this->settings->set(Doctrine2KnownSettingsEnum::OUTBOX_ENDPOINT_ID, $endpointId);
 }
 /**
  * @return string
  */
 private function getLocalAddress()
 {
     return $this->settings->get(KnownSettingsEnum::LOCAL_ADDRESS);
 }
Пример #20
0
 /**
  * @param Settings $settings
  *
  * @return int
  */
 private function getMaxRetries(Settings $settings)
 {
     $maxRetries = $settings->tryGet(KnownSettingsEnum::MAX_FLR_RETRIES);
     $maxRetries = $maxRetries === null ? self::DEFAULT_MAX_RETRIES : $maxRetries;
     return $maxRetries;
 }
 public static function isFeatureActive($featureFqcn, Settings $settings)
 {
     return $settings->tryGet($featureFqcn) == FeatureStateEnum::ACTIVE;
 }