Skip to content

Commit 1c77a6b

Browse files
committed
[client] DelayRedeliveredMessageExtension should do nothing if status already set
fixes #36
1 parent 488c534 commit 1c77a6b

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Diff for: pkg/enqueue/Client/ConsumptionExtension/DelayRedeliveredMessageExtension.php

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public function onPreReceived(Context $context)
4545
if (false == $message->isRedelivered()) {
4646
return;
4747
}
48+
if (false != $context->getResult()) {
49+
return;
50+
}
4851

4952
$delayedMessage = $this->driver->createClientMessage($message);
5053

Diff for: pkg/enqueue/Consumption/ExtensionInterface.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public function onBeforeReceive(Context $context);
2424
/**
2525
* Executed when a new message is received from a broker but before it was passed to processor
2626
* The context contains a message.
27-
* The extension may set a status.
28-
* The consumption could be interrupted at this step but it will done only after the message is processed.
27+
* The extension may set a status. If the status is set the exception is thrown
28+
* The consumption could be interrupted at this step but it exits after the message is processed.
2929
*
3030
* @param Context $context
3131
*/
3232
public function onPreReceived(Context $context);
3333

3434
/**
3535
* Executed when a message is processed by a processor.
36-
* The context contains a message status and could be changed
37-
* The consumption could be interrupted at this step but it will done only after the message is processed.
36+
* The context contains a status, which could not be changed.
37+
* The consumption could be interrupted at this step but it exits after the message is processed.
3838
*
3939
* @param Context $context
4040
*/

Diff for: pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ public function testShouldDoNothingIfMessageIsNotRedelivered()
9797
self::assertNull($context->getResult());
9898
}
9999

100+
public function testShouldDoNothingIfMessageIsRedeliveredButResultWasAlreadySetOnContext()
101+
{
102+
$message = new NullMessage();
103+
$message->setRedelivered(true);
104+
105+
$driver = $this->createDriverMock();
106+
$driver
107+
->expects(self::never())
108+
->method('sendToProcessor')
109+
;
110+
111+
$context = new Context($this->createPsrContextMock());
112+
$context->setPsrMessage($message);
113+
$context->setResult('aStatus');
114+
115+
$extension = new DelayRedeliveredMessageExtension($driver, 12345);
116+
$extension->onPreReceived($context);
117+
}
118+
100119
/**
101120
* @return \PHPUnit_Framework_MockObject_MockObject|DriverInterface
102121
*/

0 commit comments

Comments
 (0)