Passed
Pull Request — master (#365)
by Dmitry
21:01
created

getPyzSynchronizationQueueConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 28
rs 9.504
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace Pyz\Client\RabbitMq;
9
10
use Spryker\Client\RabbitMq\RabbitMqConfig as SprykerRabbitMqConfig;
11
use Spryker\Shared\AssetStorage\AssetStorageConfig;
12
use Spryker\Shared\AvailabilityStorage\AvailabilityStorageConfig;
13
use Spryker\Shared\AvailabilityStorage\AvailabilityStorageConstants;
14
use Spryker\Shared\CategoryPageSearch\CategoryPageSearchConstants;
15
use Spryker\Shared\CategoryStorage\CategoryStorageConstants;
16
use Spryker\Shared\CmsPageSearch\CmsPageSearchConstants;
17
use Spryker\Shared\CmsStorage\CmsStorageConstants;
18
use Spryker\Shared\ConfigurableBundlePageSearch\ConfigurableBundlePageSearchConfig;
19
use Spryker\Shared\ConfigurableBundleStorage\ConfigurableBundleStorageConfig;
20
use Spryker\Shared\ContentStorage\ContentStorageConfig;
21
use Spryker\Shared\CustomerAccessStorage\CustomerAccessStorageConstants;
22
use Spryker\Shared\CustomerStorage\CustomerStorageConfig;
23
use Spryker\Shared\Event\EventConfig;
24
use Spryker\Shared\Event\EventConstants;
25
use Spryker\Shared\FileManagerStorage\FileManagerStorageConstants;
26
use Spryker\Shared\GlossaryStorage\GlossaryStorageConfig;
27
use Spryker\Shared\Log\LogConstants;
28
use Spryker\Shared\PriceProductStorage\PriceProductStorageConfig;
29
use Spryker\Shared\PriceProductStorage\PriceProductStorageConstants;
30
use Spryker\Shared\ProductConfigurationStorage\ProductConfigurationStorageConfig;
31
use Spryker\Shared\ProductImageStorage\ProductImageStorageConfig;
32
use Spryker\Shared\ProductPageSearch\ProductPageSearchConfig;
33
use Spryker\Shared\ProductPageSearch\ProductPageSearchConstants;
34
use Spryker\Shared\ProductStorage\ProductStorageConfig;
35
use Spryker\Shared\ProductStorage\ProductStorageConstants;
36
use Spryker\Shared\PublishAndSynchronizeHealthCheck\PublishAndSynchronizeHealthCheckConfig;
37
use Spryker\Shared\PublishAndSynchronizeHealthCheckSearch\PublishAndSynchronizeHealthCheckSearchConfig;
38
use Spryker\Shared\PublishAndSynchronizeHealthCheckStorage\PublishAndSynchronizeHealthCheckStorageConfig;
39
use Spryker\Shared\Publisher\PublisherConfig;
40
use Spryker\Shared\RabbitMq\RabbitMqEnv;
41
use Spryker\Shared\SalesReturnSearch\SalesReturnSearchConfig;
42
use Spryker\Shared\SearchHttp\SearchHttpConfig;
43
use Spryker\Shared\StoreStorage\StoreStorageConfig;
44
use Spryker\Shared\TaxProductStorage\TaxProductStorageConfig;
45
use Spryker\Shared\TaxStorage\TaxStorageConfig;
46
use Spryker\Shared\UrlStorage\UrlStorageConfig;
47
use Spryker\Shared\UrlStorage\UrlStorageConstants;
48
49
/**
50
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
51
 */
52
class RabbitMqConfig extends SprykerRabbitMqConfig
53
{
54
    /**
55
     * @return array<string, array<int, string>>
56
     */
57
    public function getQueuePools(): array
58
    {
59
        return [
60
            'synchronizationPool' => $this->getQueueConnectionNames(),
61
        ];
62
    }
63
64
    /**
65
     * @return string|null
66
     */
67
    public function getDefaultLocaleCode(): ?string
68
    {
69
        return 'en_US';
70
    }
71
72
    /**
73
     *  QueueNameFoo, // Queue => QueueNameFoo, (Queue and error queue will be created: QueueNameFoo and QueueNameFoo.error)
74
     *  QueueNameBar => [
75
     *       RoutingKeyFoo => QueueNameBaz, // (Additional queues can be defined by several routing keys)
76
     *   ],
77
     *
78
     * @see https://www.rabbitmq.com/tutorials/amqp-concepts.html
79
     *
80
     * @return array<mixed>
81
     */
82
    protected function getQueueConfiguration(): array
83
    {
84
        return array_merge(
85
            [
86
                EventConstants::EVENT_QUEUE => [
87
                    EventConfig::EVENT_ROUTING_KEY_RETRY => EventConstants::EVENT_QUEUE_RETRY,
88
                    EventConfig::EVENT_ROUTING_KEY_ERROR => EventConstants::EVENT_QUEUE_ERROR,
89
                ],
90
                $this->get(LogConstants::LOG_QUEUE_NAME),
91
            ],
92
            $this->getPublishQueueConfiguration(),
93
            $this->getSynchronizationQueueConfiguration(),
94
        );
95
    }
96
97
    /**
98
     * @return array<mixed>
99
     */
100
    protected function getPublishQueueConfiguration(): array
101
    {
102
        return [
103
            PublisherConfig::PUBLISH_QUEUE => [
104
                PublisherConfig::PUBLISH_ROUTING_KEY_RETRY => PublisherConfig::PUBLISH_RETRY_QUEUE,
105
                PublisherConfig::PUBLISH_ROUTING_KEY_ERROR => PublisherConfig::PUBLISH_ERROR_QUEUE,
106
            ],
107
            GlossaryStorageConfig::PUBLISH_TRANSLATION,
108
            PublishAndSynchronizeHealthCheckConfig::PUBLISH_PUBLISH_AND_SYNCHRONIZE_HEALTH_CHECK,
109
            UrlStorageConfig::PUBLISH_URL,
110
            AvailabilityStorageConfig::PUBLISH_AVAILABILITY,
111
            PriceProductStorageConfig::PUBLISH_PRICE_PRODUCT_ABSTRACT,
112
            PriceProductStorageConfig::PUBLISH_PRICE_PRODUCT_CONCRETE,
113
            ProductImageStorageConfig::PUBLISH_PRODUCT_ABSTRACT_IMAGE,
114
            ProductImageStorageConfig::PUBLISH_PRODUCT_CONCRETE_IMAGE,
115
            ProductPageSearchConfig::PUBLISH_PRODUCT_ABSTRACT_PAGE,
116
            ProductPageSearchConfig::PUBLISH_PRODUCT_CONCRETE_PAGE,
117
            ProductStorageConfig::PUBLISH_PRODUCT_ABSTRACT,
118
            ProductStorageConfig::PUBLISH_PRODUCT_CONCRETE,
119
            CustomerStorageConfig::PUBLISH_CUSTOMER_INVALIDATED,
120
        ];
121
    }
122
123
    /**
124
     * @return array<mixed>
125
     */
126
    protected function getSynchronizationQueueConfiguration(): array
127
    {
128
        return [
129
            PublishAndSynchronizeHealthCheckSearchConfig::SYNC_SEARCH_PUBLISH_AND_SYNCHRONIZE_HEALTH_CHECK,
130
            PublishAndSynchronizeHealthCheckStorageConfig::SYNC_STORAGE_PUBLISH_AND_SYNCHRONIZE_HEALTH_CHECK,
131
            GlossaryStorageConfig::SYNC_STORAGE_TRANSLATION,
132
            UrlStorageConstants::URL_SYNC_STORAGE_QUEUE,
133
            AvailabilityStorageConstants::AVAILABILITY_SYNC_STORAGE_QUEUE,
134
            CustomerAccessStorageConstants::CUSTOMER_ACCESS_SYNC_STORAGE_QUEUE,
135
            CustomerStorageConfig::CUSTOMER_INVALIDATED_SYNC_STORAGE_QUEUE,
136
            CategoryStorageConstants::CATEGORY_SYNC_STORAGE_QUEUE,
137
            ProductStorageConstants::PRODUCT_SYNC_STORAGE_QUEUE,
138
            PriceProductStorageConstants::PRICE_SYNC_STORAGE_QUEUE,
139
            ConfigurableBundleStorageConfig::CONFIGURABLE_BUNDLE_SYNC_STORAGE_QUEUE,
140
            ConfigurableBundlePageSearchConfig::CONFIGURABLE_BUNDLE_SEARCH_QUEUE,
141
            CmsStorageConstants::CMS_SYNC_STORAGE_QUEUE,
142
            CategoryPageSearchConstants::CATEGORY_SYNC_SEARCH_QUEUE,
143
            CmsPageSearchConstants::CMS_SYNC_SEARCH_QUEUE,
144
            ProductPageSearchConstants::PRODUCT_SYNC_SEARCH_QUEUE,
145
            FileManagerStorageConstants::FILE_SYNC_STORAGE_QUEUE,
146
            ContentStorageConfig::CONTENT_SYNC_STORAGE_QUEUE,
147
            TaxProductStorageConfig::PRODUCT_ABSTRACT_TAX_SET_SYNC_STORAGE_QUEUE,
148
            TaxStorageConfig::TAX_SET_SYNC_STORAGE_QUEUE,
149
            SalesReturnSearchConfig::SYNC_SEARCH_RETURN,
150
            StoreStorageConfig::STORE_SYNC_STORAGE_QUEUE,
151
            AssetStorageConfig::ASSET_SYNC_STORAGE_QUEUE,
152
            ProductConfigurationStorageConfig::PRODUCT_CONFIGURATION_SYNC_STORAGE_QUEUE,
153
            SearchHttpConfig::SEARCH_HTTP_CONFIG_SYNC_QUEUE,
154
        ];
155
    }
156
157
    /**
158
     * @return string
159
     */
160
    protected function getDefaultBoundQueueNamePrefix(): string
161
    {
162
        return 'error';
163
    }
164
165
    /**
166
     * @return array<string>
167
     */
168
    protected function getQueueConnectionNames(): array
169
    {
170
        return array_map(
171
            function (array $connection): string {
172
                return $connection[RabbitMqEnv::RABBITMQ_CONNECTION_NAME];
173
            },
174
            $this->get(RabbitMqEnv::RABBITMQ_CONNECTIONS),
175
        );
176
    }
177
}
178