Skip to content

Commit 7e41edd

Browse files
Dnyaneshwar S JambhulkarDnyaneshwar S Jambhulkar
authored andcommitted
AC-14558::Migration form RabbitMQ to Apache ActiveMQ
1 parent 35c0b76 commit 7e41edd

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

lib/internal/Magento/Framework/MessageQueue/Consumer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ private function sendResponse(EnvelopeInterface $envelope)
210210
$messageProperties = $envelope->getProperties();
211211
$connectionName = $this->consumerConfig->getConsumer($this->configuration->getConsumerName())->getConnection();
212212
$queue = $this->queueRepository->get($connectionName, $messageProperties['reply_to']);
213-
$queue->callRpc($envelope);
213+
if($connectionName === 'stomp') {
214+
$queue->callRpc($envelope);
215+
} else {
216+
$queue->push($envelope);
217+
}
214218
}
215219

216220
/**

lib/internal/Magento/Framework/MessageQueue/Test/Unit/ConsumerTest.php

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use PHPUnit\Framework\MockObject\MockObject;
2727
use PHPUnit\Framework\TestCase;
2828
use Psr\Log\LoggerInterface;
29+
use Magento\Framework\MessageQueue\DefaultValueProvider;
2930

3031
/**
3132
* Unit test for Consumer class.
@@ -99,6 +100,11 @@ class ConsumerTest extends TestCase
99100
*/
100101
private $deploymentConfig;
101102

103+
/**
104+
* @var DefaultValueProvider|MockObject
105+
*/
106+
private $defaultValueProvider;
107+
102108
/**
103109
* Set up.
104110
*
@@ -123,6 +129,7 @@ protected function setUp(): void
123129
->disableOriginalConstructor()
124130
->getMockForAbstractClass();
125131
$this->deploymentConfig = $this->createMock(DeploymentConfig::class);
132+
$this->defaultValueProvider = $this->createMock(DefaultValueProvider::class);
126133

127134
$objectManager = new ObjectManager($this);
128135
$this->poisonPillCompare = $this->getMockBuilder(PoisonPillCompareInterface::class)
@@ -135,7 +142,8 @@ protected function setUp(): void
135142
$this->callbackInvoker = new CallbackInvoker(
136143
$this->poisonPillRead,
137144
$this->poisonPillCompare,
138-
$this->deploymentConfig
145+
$this->deploymentConfig,
146+
$this->defaultValueProvider
139147
);
140148
$this->consumer = $objectManager->getObject(
141149
Consumer::class,
@@ -182,12 +190,15 @@ protected function setUp(): void
182190
public function testProcessWithNotFoundException()
183191
{
184192
$properties = ['topic_name' => 'topic.name'];
185-
$topicConfig = [];
193+
$topicConfig = ['is_synchronous' => true];
186194
$numberOfMessages = 1;
187195
$consumerName = 'consumer.name';
188196
$exceptionPhrase = new Phrase('Exception successfully thrown');
189197
$this->poisonPillRead->expects($this->atLeastOnce())->method('getLatestVersion')->willReturn('version-1');
190198
$this->poisonPillCompare->expects($this->atLeastOnce())->method('isLatestVersion')->willReturn(true);
199+
$this->defaultValueProvider->expects($this->once())->method('getConnection')->willReturn('db');
200+
$this->deploymentConfig->expects($this->any())->method('get')
201+
->with('queue/consumers_wait_for_messages', 1)->willReturn(1);
191202
$queue = $this->getMockBuilder(QueueInterface::class)
192203
->disableOriginalConstructor()
193204
->getMockForAbstractClass();
@@ -200,14 +211,6 @@ public function testProcessWithNotFoundException()
200211
$this->communicationConfig->expects($this->once())->method('getTopic')->with($properties['topic_name'])
201212
->willReturn($topicConfig);
202213
$this->configuration->expects($this->atLeastOnce())->method('getConsumerName')->willReturn($consumerName);
203-
$consumerConfigItem = $this->getMockBuilder(
204-
\Magento\Framework\MessageQueue\Consumer\Config\ConsumerConfigItemInterface::class
205-
)
206-
->disableOriginalConstructor()
207-
->getMockForAbstractClass();
208-
$consumerConfigItem->expects($this->once())->method('getConnection')->willReturn('connection_name');
209-
$this->consumerConfig->expects($this->once())->method('getConsumer')->with($consumerName)
210-
->willReturn($consumerConfigItem);
211214
$this->messageController->expects($this->once())->method('lock')->with($envelope, $consumerName)
212215
->willThrowException(
213216
new NotFoundException(
@@ -228,23 +231,17 @@ public function testProcessWithNotFoundException()
228231
public function testProcessWithGetMaxIdleTimeAndGetSleepConsumerConfigurations()
229232
{
230233
$numberOfMessages = 1;
231-
$this->poisonPillRead->expects($this->atLeastOnce())->method('getLatestVersion');
234+
$this->poisonPillRead->expects($this->atLeastOnce())->method('getLatestVersion')->willReturn('version-1');
235+
$this->poisonPillCompare->expects($this->any())->method('isLatestVersion')->willReturn(true);
236+
$this->defaultValueProvider->expects($this->once())->method('getConnection')->willReturn('db');
237+
$this->deploymentConfig->expects($this->any())->method('get')
238+
->with('queue/consumers_wait_for_messages', 1)->willReturn(1);
232239
$queue = $this->getMockBuilder(\Magento\Framework\MessageQueue\QueueInterface::class)
233240
->disableOriginalConstructor()->getMock();
234241
$this->configuration->expects($this->once())->method('getQueue')->willReturn($queue);
235242
$queue->expects($this->atMost(2))->method('dequeue')->willReturn(null);
236243
$this->configuration->expects($this->once())->method('getMaxIdleTime')->willReturn('2');
237244
$this->configuration->expects($this->once())->method('getSleep')->willReturn('2');
238-
$consumerName = 'consumer.name';
239-
$this->configuration->expects($this->once())->method('getConsumerName')->willReturn($consumerName);
240-
$consumerConfigItem = $this->getMockBuilder(
241-
\Magento\Framework\MessageQueue\Consumer\Config\ConsumerConfigItemInterface::class
242-
)
243-
->disableOriginalConstructor()
244-
->getMockForAbstractClass();
245-
$consumerConfigItem->expects($this->once())->method('getConnection')->willReturn('connection_name');
246-
$this->consumerConfig->expects($this->once())->method('getConsumer')->with($consumerName)
247-
->willReturn($consumerConfigItem);
248245
$this->consumer->process($numberOfMessages);
249246
}
250247
}

0 commit comments

Comments
 (0)