File tree Expand file tree Collapse file tree 11 files changed +119
-171
lines changed
Expand file tree Collapse file tree 11 files changed +119
-171
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ interface ConsumerInterceptor
2121 */
2222 public function onStartup (): void ;
2323
24+ /**
25+ * Do some one time action when the consumer is shutting down
26+ */
27+ public function onShutdown (): void ;
28+
2429 /**
2530 * should this consumer be stopped before next run
2631 */
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Ecotone \Messaging \Endpoint ;
6+
7+ use Throwable ;
8+
9+ /**
10+ * licence Apache-2.0
11+ */
12+ trait ConsumerInterceptorTrait
13+ {
14+ public function onStartup (): void {}
15+
16+ public function onShutdown (): void {}
17+
18+ public function shouldBeStopped (): bool {
19+ return false ;
20+ }
21+
22+ public function shouldBeThrown (Throwable $ exception ): bool
23+ {
24+ return false ;
25+ }
26+
27+ public function preRun (): void {
28+
29+ }
30+
31+ /**
32+ * Called after each run
33+ */
34+ public function postRun (?Throwable $ unhandledFailure ): void
35+ {}
36+
37+ /**
38+ * Called after each sending message to request channel
39+ */
40+ public function postSend (): void
41+ {}
42+ }
Original file line number Diff line number Diff line change 55namespace Ecotone \Messaging \Endpoint \Interceptor ;
66
77use Ecotone \Messaging \Endpoint \ConsumerInterceptor ;
8+ use Ecotone \Messaging \Endpoint \ConsumerInterceptorTrait ;
89use Ecotone \Messaging \Endpoint \PollingConsumer \ConnectionException ;
910use Ecotone \Messaging \Handler \Recoverability \RetryTemplateBuilder ;
1011use Ecotone \Messaging \Scheduling \Duration ;
1718 */
1819class ConnectionExceptionRetryInterceptor implements ConsumerInterceptor
1920{
21+ use ConsumerInterceptorTrait;
2022 private int $ currentNumberOfRetries = 0 ;
2123 private ?\Ecotone \Messaging \Handler \Recoverability \RetryTemplate $ retryTemplate ;
2224
@@ -33,14 +35,6 @@ public function onStartup(): void
3335 $ this ->currentNumberOfRetries = 0 ;
3436 }
3537
36- /**
37- * @inheritDoc
38- */
39- public function shouldBeStopped (): bool
40- {
41- return false ;
42- }
43-
4438 /**
4539 * @inheritDoc
4640 */
@@ -87,11 +81,4 @@ public function postRun(?Throwable $unhandledFailure): void
8781
8882 $ this ->currentNumberOfRetries = 0 ;
8983 }
90-
91- /**
92- * @inheritDoc
93- */
94- public function postSend (): void
95- {
96- }
9784}
Original file line number Diff line number Diff line change 55namespace Ecotone \Messaging \Endpoint \Interceptor ;
66
77use Ecotone \Messaging \Endpoint \ConsumerInterceptor ;
8+ use Ecotone \Messaging \Endpoint \ConsumerInterceptorTrait ;
89use Ecotone \Messaging \Scheduling \DatePoint ;
910use Ecotone \Messaging \Scheduling \Duration ;
1011use Ecotone \Messaging \Scheduling \EcotoneClockInterface ;
1516 */
1617class FinishWhenNoMessagesInterceptor implements ConsumerInterceptor
1718{
19+ use ConsumerInterceptorTrait;
1820 private bool $ shouldBeStopped = false ;
1921 private ?DatePoint $ lastTimeMessageWasReceived ;
2022
@@ -38,14 +40,6 @@ public function preRun(): void
3840 $ this ->shouldBeStopped = true ;
3941 }
4042
41- /**
42- * @inheritDoc
43- */
44- public function shouldBeThrown (Throwable $ exception ): bool
45- {
46- return false ;
47- }
48-
4943 /**
5044 * @inheritDoc
5145 */
@@ -62,13 +56,6 @@ public function shouldBeStopped(): bool
6256 return $ this ->shouldBeStopped ;
6357 }
6458
65- /**
66- * @inheritDoc
67- */
68- public function postRun (?Throwable $ unhandledFailure ): void
69- {
70- }
71-
7259 /**
7360 * @inheritDoc
7461 */
Original file line number Diff line number Diff line change 55namespace Ecotone \Messaging \Endpoint \Interceptor ;
66
77use Ecotone \Messaging \Endpoint \ConsumerInterceptor ;
8+ use Ecotone \Messaging \Endpoint \ConsumerInterceptorTrait ;
89use Throwable ;
910
1011/**
1718 */
1819class LimitConsumedMessagesInterceptor implements ConsumerInterceptor
1920{
21+ use ConsumerInterceptorTrait;
2022 private bool $ shouldBeStopped = false ;
2123
2224 private int $ currentConsumedMessages = 0 ;
@@ -41,21 +43,6 @@ public function onStartup(): void
4143 $ this ->shouldBeStopped = false ;
4244 }
4345
44- /**
45- * @inheritDoc
46- */
47- public function preRun (): void
48- {
49- }
50-
51- /**
52- * @inheritDoc
53- */
54- public function shouldBeThrown (Throwable $ exception ): bool
55- {
56- return false ;
57- }
58-
5946 /**
6047 * @inheritDoc
6148 */
Original file line number Diff line number Diff line change 55namespace Ecotone \Messaging \Endpoint \Interceptor ;
66
77use Ecotone \Messaging \Endpoint \ConsumerInterceptor ;
8+ use Ecotone \Messaging \Endpoint \ConsumerInterceptorTrait ;
89use Throwable ;
910
1011/**
1718 */
1819class LimitExecutionAmountInterceptor implements ConsumerInterceptor
1920{
21+ use ConsumerInterceptorTrait;
22+
2023 private bool $ shouldBeStopped = false ;
2124
2225 private int $ currentExecutionAmount = 0 ;
@@ -41,21 +44,6 @@ public function onStartup(): void
4144 $ this ->shouldBeStopped = false ;
4245 }
4346
44- /**
45- * @inheritDoc
46- */
47- public function preRun (): void
48- {
49- }
50-
51- /**
52- * @inheritDoc
53- */
54- public function shouldBeThrown (Throwable $ exception ): bool
55- {
56- return false ;
57- }
58-
5947 /**
6048 * @inheritDoc
6149 */
@@ -72,11 +60,4 @@ public function postRun(?Throwable $unhandledFailure): void
7260 $ this ->currentExecutionAmount ++;
7361 $ this ->shouldBeStopped = $ this ->currentExecutionAmount >= $ this ->executionLimit ;
7462 }
75-
76- /**
77- * @inheritDoc
78- */
79- public function postSend (): void
80- {
81- }
8263}
Original file line number Diff line number Diff line change 66
77use Ecotone \Messaging \Config \ConfigurationException ;
88use Ecotone \Messaging \Endpoint \ConsumerInterceptor ;
9+ use Ecotone \Messaging \Endpoint \ConsumerInterceptorTrait ;
910use Throwable ;
1011
1112/**
1819 */
1920class LimitMemoryUsageInterceptor implements ConsumerInterceptor
2021{
22+ use ConsumerInterceptorTrait;
2123 private int $ memoryLimitInMegaBytes ;
2224
2325 /**
@@ -34,13 +36,6 @@ public function __construct(int $memoryLimitInMegaBytes)
3436 $ this ->memoryLimitInMegaBytes = $ memoryLimitInMegaBytes * 1024 * 1024 ;
3537 }
3638
37- /**
38- * @inheritDoc
39- */
40- public function onStartup (): void
41- {
42- }
43-
4439 /**
4540 * @inheritDoc
4641 */
@@ -52,33 +47,4 @@ public function shouldBeStopped(): bool
5247
5348 return memory_get_usage (true ) >= $ this ->memoryLimitInMegaBytes ;
5449 }
55-
56- /**
57- * @inheritDoc
58- */
59- public function shouldBeThrown (Throwable $ exception ): bool
60- {
61- return false ;
62- }
63-
64- /**
65- * @inheritDoc
66- */
67- public function preRun (): void
68- {
69- }
70-
71- /**
72- * @inheritDoc
73- */
74- public function postRun (?Throwable $ unhandledFailure ): void
75- {
76- }
77-
78- /**
79- * @inheritDoc
80- */
81- public function postSend (): void
82- {
83- }
8450}
You can’t perform that action at this time.
0 commit comments