3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Framework \MessageQueue \Rpc ;
7
8
8
- use Magento \Framework \MessageQueue \ PublisherInterface ;
9
+ use Magento \Framework \App \ ObjectManager ;
9
10
use Magento \Framework \MessageQueue \EnvelopeFactory ;
10
11
use Magento \Framework \MessageQueue \ExchangeRepository ;
11
12
use Magento \Framework \MessageQueue \MessageEncoder ;
12
13
use Magento \Framework \MessageQueue \MessageValidator ;
13
14
use Magento \Framework \MessageQueue \Publisher \ConfigInterface as PublisherConfig ;
15
+ use Magento \Framework \MessageQueue \PublisherInterface ;
14
16
15
17
/**
16
18
* A MessageQueue Publisher to handle publishing a message.
@@ -49,27 +51,42 @@ class Publisher implements PublisherInterface
49
51
*/
50
52
private $ publisherConfig ;
51
53
52
- //@codingStandardsIgnoreStart
53
54
/**
54
55
* Initialize dependencies.
55
56
*
56
57
* @param ExchangeRepository $exchangeRepository
57
58
* @param EnvelopeFactory $envelopeFactory
58
- * @param MessageEncoder $messageEncoder
59
- * @param MessageValidator $messageValidator
59
+ * @param null $messageQueueConfig @deprecated obsolete dependency
60
+ * @param null $amqpConfig @deprecated obsolete dependency
61
+ * @param MessageEncoder|null $messageEncoder
62
+ * @param MessageValidator|null $messageValidator
63
+ * @param ResponseQueueNameBuilder|null $responseQueueNameBuilder
64
+ * @param PublisherConfig|null $publisherConfig
65
+ *
66
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
60
67
*/
61
68
public function __construct (
62
69
ExchangeRepository $ exchangeRepository ,
63
70
EnvelopeFactory $ envelopeFactory ,
64
- MessageEncoder $ messageEncoder ,
65
- MessageValidator $ messageValidator
71
+ $ messageQueueConfig = null ,
72
+ $ amqpConfig = null ,
73
+ MessageEncoder $ messageEncoder = null ,
74
+ MessageValidator $ messageValidator = null ,
75
+ ResponseQueueNameBuilder $ responseQueueNameBuilder = null ,
76
+ PublisherConfig $ publisherConfig = null
66
77
) {
67
78
$ this ->exchangeRepository = $ exchangeRepository ;
68
79
$ this ->envelopeFactory = $ envelopeFactory ;
69
- $ this ->messageEncoder = $ messageEncoder ;
70
- $ this ->messageValidator = $ messageValidator ;
80
+ $ objectManager = ObjectManager::getInstance ();
81
+ $ this ->messageEncoder = $ messageEncoder
82
+ ?? $ objectManager ->get (MessageEncoder::class);
83
+ $ this ->messageValidator = $ messageValidator
84
+ ?? $ objectManager ->get (MessageValidator::class);
85
+ $ this ->responseQueueNameBuilder = $ responseQueueNameBuilder
86
+ ?? $ objectManager ->get (ResponseQueueNameBuilder::class);
87
+ $ this ->publisherConfig = $ publisherConfig
88
+ ?? $ objectManager ->get (PublisherConfig::class);
71
89
}
72
- //@codingStandardsIgnoreEnd
73
90
74
91
/**
75
92
* @inheritdoc
@@ -78,7 +95,7 @@ public function publish($topicName, $data)
78
95
{
79
96
$ this ->messageValidator ->validate ($ topicName , $ data );
80
97
$ data = $ this ->messageEncoder ->encode ($ topicName , $ data );
81
- $ replyTo = $ this ->getResponseQueueNameBuilder () ->getQueueName ($ topicName );
98
+ $ replyTo = $ this ->responseQueueNameBuilder ->getQueueName ($ topicName );
82
99
$ envelope = $ this ->envelopeFactory ->create (
83
100
[
84
101
'body ' => $ data ,
@@ -92,40 +109,9 @@ public function publish($topicName, $data)
92
109
]
93
110
]
94
111
);
95
- $ connectionName = $ this ->getPublisherConfig () ->getPublisher ($ topicName )->getConnection ()->getName ();
112
+ $ connectionName = $ this ->publisherConfig ->getPublisher ($ topicName )->getConnection ()->getName ();
96
113
$ exchange = $ this ->exchangeRepository ->getByConnectionName ($ connectionName );
97
114
$ responseMessage = $ exchange ->enqueue ($ topicName , $ envelope );
98
115
return $ this ->messageEncoder ->decode ($ topicName , $ responseMessage , false );
99
116
}
100
-
101
- /**
102
- * Get response queue name builder.
103
- *
104
- * @return ResponseQueueNameBuilder
105
- *
106
- * @deprecated 103.0.0
107
- */
108
- private function getResponseQueueNameBuilder ()
109
- {
110
- if ($ this ->responseQueueNameBuilder === null ) {
111
- $ this ->responseQueueNameBuilder = \Magento \Framework \App \ObjectManager::getInstance ()
112
- ->get (ResponseQueueNameBuilder::class);
113
- }
114
- return $ this ->responseQueueNameBuilder ;
115
- }
116
-
117
- /**
118
- * Get publisher config.
119
- *
120
- * @return PublisherConfig
121
- *
122
- * @deprecated 103.0.0
123
- */
124
- private function getPublisherConfig ()
125
- {
126
- if ($ this ->publisherConfig === null ) {
127
- $ this ->publisherConfig = \Magento \Framework \App \ObjectManager::getInstance ()->get (PublisherConfig::class);
128
- }
129
- return $ this ->publisherConfig ;
130
- }
131
117
}
0 commit comments