Passed
Pull Request — master (#213)
by Ruslan
18:45
created

getSynchronizationQueueConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 37
c 0
b 0
f 0
rs 9.36
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\CompanyUserStorage\CompanyUserStorageConfig;
19
use Spryker\Shared\ConfigurableBundlePageSearch\ConfigurableBundlePageSearchConfig;
20
use Spryker\Shared\ConfigurableBundleStorage\ConfigurableBundleStorageConfig;
21
use Spryker\Shared\ContentStorage\ContentStorageConfig;
22
use Spryker\Shared\CustomerAccessStorage\CustomerAccessStorageConstants;
23
use Spryker\Shared\CustomerStorage\CustomerStorageConfig;
24
use Spryker\Shared\Event\EventConfig;
25
use Spryker\Shared\Event\EventConstants;
26
use Spryker\Shared\FileManagerStorage\FileManagerStorageConstants;
27
use Spryker\Shared\GlossaryStorage\GlossaryStorageConfig;
28
use Spryker\Shared\Log\LogConstants;
29
use Spryker\Shared\MerchantOpeningHoursStorage\MerchantOpeningHoursStorageConfig;
30
use Spryker\Shared\MerchantSearch\MerchantSearchConfig;
31
use Spryker\Shared\MerchantStorage\MerchantStorageConfig;
32
use Spryker\Shared\PriceProductOfferStorage\PriceProductOfferStorageConfig;
33
use Spryker\Shared\PriceProductStorage\PriceProductStorageConfig;
34
use Spryker\Shared\PriceProductStorage\PriceProductStorageConstants;
35
use Spryker\Shared\ProductConfigurationStorage\ProductConfigurationStorageConfig;
36
use Spryker\Shared\ProductImageStorage\ProductImageStorageConfig;
37
use Spryker\Shared\ProductOfferAvailabilityStorage\ProductOfferAvailabilityStorageConfig;
38
use Spryker\Shared\ProductOfferStorage\ProductOfferStorageConfig;
39
use Spryker\Shared\ProductPackagingUnitStorage\ProductPackagingUnitStorageConfig;
40
use Spryker\Shared\ProductPageSearch\ProductPageSearchConfig;
41
use Spryker\Shared\ProductPageSearch\ProductPageSearchConstants;
42
use Spryker\Shared\ProductStorage\ProductStorageConfig;
43
use Spryker\Shared\ProductStorage\ProductStorageConstants;
44
use Spryker\Shared\PublishAndSynchronizeHealthCheck\PublishAndSynchronizeHealthCheckConfig;
45
use Spryker\Shared\PublishAndSynchronizeHealthCheckSearch\PublishAndSynchronizeHealthCheckSearchConfig;
46
use Spryker\Shared\PublishAndSynchronizeHealthCheckStorage\PublishAndSynchronizeHealthCheckStorageConfig;
47
use Spryker\Shared\Publisher\PublisherConfig;
48
use Spryker\Shared\RabbitMq\RabbitMqEnv;
49
use Spryker\Shared\SalesReturnSearch\SalesReturnSearchConfig;
50
use Spryker\Shared\SearchHttp\SearchHttpConfig;
51
use Spryker\Shared\ShoppingListStorage\ShoppingListStorageConfig;
52
use Spryker\Shared\StoreStorage\StoreStorageConfig;
53
use Spryker\Shared\TaxProductStorage\TaxProductStorageConfig;
54
use Spryker\Shared\TaxStorage\TaxStorageConfig;
55
use Spryker\Shared\UrlStorage\UrlStorageConfig;
56
use Spryker\Shared\UrlStorage\UrlStorageConstants;
57
58
/**
59
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
60
 */
61
class RabbitMqConfig extends SprykerRabbitMqConfig
62
{
63
    /**
64
     * @return array<string, array<int, string>>
65
     */
66
    public function getQueuePools(): array
67
    {
68
        return [
69
            'synchronizationPool' => $this->getQueueConnectionNames(),
70
        ];
71
    }
72
73
    /**
74
     * @return string|null
75
     */
76
    public function getDefaultLocaleCode(): ?string
77
    {
78
        return 'en_US';
79
    }
80
81
    /**
82
     *  QueueNameFoo, // Queue => QueueNameFoo, (Queue and error queue will be created: QueueNameFoo and QueueNameFoo.error)
83
     *  QueueNameBar => [
84
     *       RoutingKeyFoo => QueueNameBaz, // (Additional queues can be defined by several routing keys)
85
     *   ],
86
     *
87
     * @see https://www.rabbitmq.com/tutorials/amqp-concepts.html
88
     *
89
     * @return array<mixed>
90
     */
91
    protected function getQueueConfiguration(): array
92
    {
93
        return array_merge(
94
            [
95
                EventConstants::EVENT_QUEUE => [
96
                    EventConfig::EVENT_ROUTING_KEY_RETRY => EventConstants::EVENT_QUEUE_RETRY,
97
                    EventConfig::EVENT_ROUTING_KEY_ERROR => EventConstants::EVENT_QUEUE_ERROR,
98
                ],
99
                $this->get(LogConstants::LOG_QUEUE_NAME),
100
            ],
101
            $this->getPublishQueueConfiguration(),
102
            $this->getSynchronizationQueueConfiguration(),
103
        );
104
    }
105
106
    /**
107
     * @return array<mixed>
108
     */
109
    protected function getPublishQueueConfiguration(): array
110
    {
111
        return [
112
            PublisherConfig::PUBLISH_QUEUE => [
113
                PublisherConfig::PUBLISH_ROUTING_KEY_RETRY => PublisherConfig::PUBLISH_RETRY_QUEUE,
114
                PublisherConfig::PUBLISH_ROUTING_KEY_ERROR => PublisherConfig::PUBLISH_ERROR_QUEUE,
115
            ],
116
            GlossaryStorageConfig::PUBLISH_TRANSLATION,
117
            PublishAndSynchronizeHealthCheckConfig::PUBLISH_PUBLISH_AND_SYNCHRONIZE_HEALTH_CHECK,
118
            UrlStorageConfig::PUBLISH_URL,
119
            AvailabilityStorageConfig::PUBLISH_AVAILABILITY,
120
            PriceProductStorageConfig::PUBLISH_PRICE_PRODUCT_ABSTRACT,
121
            PriceProductStorageConfig::PUBLISH_PRICE_PRODUCT_CONCRETE,
122
            ProductImageStorageConfig::PUBLISH_PRODUCT_ABSTRACT_IMAGE,
123
            ProductImageStorageConfig::PUBLISH_PRODUCT_CONCRETE_IMAGE,
124
            ProductPageSearchConfig::PUBLISH_PRODUCT_ABSTRACT_PAGE,
125
            ProductPageSearchConfig::PUBLISH_PRODUCT_CONCRETE_PAGE,
126
            ProductStorageConfig::PUBLISH_PRODUCT_ABSTRACT,
127
            ProductStorageConfig::PUBLISH_PRODUCT_CONCRETE,
128
            CustomerStorageConfig::PUBLISH_CUSTOMER_INVALIDATED,
129
        ];
130
    }
131
132
    /**
133
     * @return array<mixed>
134
     */
135
    protected function getSynchronizationQueueConfiguration(): array
136
    {
137
        return [
138
            PublishAndSynchronizeHealthCheckSearchConfig::SYNC_SEARCH_PUBLISH_AND_SYNCHRONIZE_HEALTH_CHECK,
139
            PublishAndSynchronizeHealthCheckStorageConfig::SYNC_STORAGE_PUBLISH_AND_SYNCHRONIZE_HEALTH_CHECK,
140
            GlossaryStorageConfig::SYNC_STORAGE_TRANSLATION,
141
            UrlStorageConstants::URL_SYNC_STORAGE_QUEUE,
142
            AvailabilityStorageConstants::AVAILABILITY_SYNC_STORAGE_QUEUE,
143
            CustomerAccessStorageConstants::CUSTOMER_ACCESS_SYNC_STORAGE_QUEUE,
144
            CustomerStorageConfig::CUSTOMER_INVALIDATED_SYNC_STORAGE_QUEUE,
145
            CategoryStorageConstants::CATEGORY_SYNC_STORAGE_QUEUE,
146
            ProductStorageConstants::PRODUCT_SYNC_STORAGE_QUEUE,
147
            PriceProductStorageConstants::PRICE_SYNC_STORAGE_QUEUE,
148
            ProductPackagingUnitStorageConfig::PRODUCT_PACKAGING_UNIT_SYNC_STORAGE_QUEUE,
149
            ConfigurableBundleStorageConfig::CONFIGURABLE_BUNDLE_SYNC_STORAGE_QUEUE,
150
            ConfigurableBundlePageSearchConfig::CONFIGURABLE_BUNDLE_SEARCH_QUEUE,
151
            CmsStorageConstants::CMS_SYNC_STORAGE_QUEUE,
152
            CategoryPageSearchConstants::CATEGORY_SYNC_SEARCH_QUEUE,
153
            CmsPageSearchConstants::CMS_SYNC_SEARCH_QUEUE,
154
            ProductPageSearchConstants::PRODUCT_SYNC_SEARCH_QUEUE,
155
            FileManagerStorageConstants::FILE_SYNC_STORAGE_QUEUE,
156
            ShoppingListStorageConfig::SHOPPING_LIST_SYNC_STORAGE_QUEUE,
157
            CompanyUserStorageConfig::COMPANY_USER_SYNC_STORAGE_QUEUE,
158
            ContentStorageConfig::CONTENT_SYNC_STORAGE_QUEUE,
159
            TaxProductStorageConfig::PRODUCT_ABSTRACT_TAX_SET_SYNC_STORAGE_QUEUE,
160
            TaxStorageConfig::TAX_SET_SYNC_STORAGE_QUEUE,
161
            SalesReturnSearchConfig::SYNC_SEARCH_RETURN,
162
            MerchantStorageConfig::MERCHANT_SYNC_STORAGE_QUEUE,
163
            MerchantSearchConfig::SYNC_SEARCH_MERCHANT,
164
            PriceProductOfferStorageConfig::PRICE_PRODUCT_OFFER_OFFER_SYNC_STORAGE_QUEUE,
165
            MerchantOpeningHoursStorageConfig::MERCHANT_OPENING_HOURS_SYNC_STORAGE_QUEUE,
166
            ProductOfferAvailabilityStorageConfig::PRODUCT_OFFER_AVAILABILITY_SYNC_STORAGE_QUEUE,
167
            ProductOfferStorageConfig::PRODUCT_OFFER_SYNC_STORAGE_QUEUE,
168
            StoreStorageConfig::STORE_SYNC_STORAGE_QUEUE,
169
            AssetStorageConfig::ASSET_SYNC_STORAGE_QUEUE,
170
            ProductConfigurationStorageConfig::PRODUCT_CONFIGURATION_SYNC_STORAGE_QUEUE,
171
            SearchHttpConfig::SEARCH_HTTP_CONFIG_SYNC_QUEUE,
172
        ];
173
    }
174
175
    /**
176
     * @return string
177
     */
178
    protected function getDefaultBoundQueueNamePrefix(): string
179
    {
180
        return 'error';
181
    }
182
183
    /**
184
     * @return array<string>
185
     */
186
    protected function getQueueConnectionNames(): array
187
    {
188
        return array_map(
189
            function (array $connection): string {
190
                return $connection[RabbitMqEnv::RABBITMQ_CONNECTION_NAME];
191
            },
192
            $this->get(RabbitMqEnv::RABBITMQ_CONNECTIONS),
193
        );
194
    }
195
}
196