88use Ecotone \Lite \Test \FlowTestSupport ;
99use Ecotone \Messaging \Config \ModulePackageList ;
1010use Ecotone \Messaging \Config \ServiceConfiguration ;
11+ use Ecotone \Messaging \Handler \Logger \EchoLogger ;
1112use Enqueue \AmqpExt \AmqpConnectionFactory ;
1213use Test \Ecotone \Amqp \AmqpMessagingTestCase ;
1314use Test \Ecotone \Amqp \Fixture \Order \OrderErrorHandler ;
@@ -42,6 +43,27 @@ public function test_products_are_on_list_after_being_ordered(): void
4243 );
4344 }
4445
46+ public function test_messages_are_delivered_after_lost_heartbeat (): void
47+ {
48+ $ ecotone = $ this ->bootstrapEcotone (
49+ namespaces: ['Test\Ecotone\Amqp\Fixture\Order ' ],
50+ services: [new OrderService (), new OrderErrorHandler (), 'logger ' => new EchoLogger ()],
51+ amqpConfig: ['heartbeat ' => 1 ]
52+ );
53+
54+ $ ecotone ->sendCommandWithRoutingKey ('order.register ' , 'milk ' );
55+ $ ecotone ->run ('orders ' );
56+ self ::assertEquals (['milk ' ], $ ecotone ->sendQueryWithRouting ('order.getOrders ' ));
57+ sleep (2 );
58+ $ ecotone ->sendCommandWithRoutingKey ('order.register ' , 'salt ' );
59+ $ ecotone ->run ('orders ' );
60+ self ::assertEquals (['milk ' , 'salt ' ], $ ecotone ->sendQueryWithRouting ('order.getOrders ' ));
61+ sleep (10 );
62+ $ ecotone ->sendCommandWithRoutingKey ('order.register ' , 'sunflower ' );
63+ $ ecotone ->run ('orders ' );
64+ self ::assertEquals (['milk ' , 'salt ' , 'sunflower ' ], $ ecotone ->sendQueryWithRouting ('order.getOrders ' ));
65+ }
66+
4567 public function test_adding_product_to_shopping_cart_with_publisher_and_consumer (): void
4668 {
4769 $ ecotone = $ this ->bootstrapEcotone (
@@ -58,10 +80,10 @@ public function test_adding_product_to_shopping_cart_with_publisher_and_consumer
5880 );
5981 }
6082
61- private function bootstrapEcotone (array $ namespaces , array $ services ): FlowTestSupport
83+ private function bootstrapEcotone (array $ namespaces , array $ services, array $ amqpConfig = [] ): FlowTestSupport
6284 {
6385 return EcotoneLite::bootstrapFlowTesting (
64- containerOrAvailableServices: array_merge ([AmqpConnectionFactory::class => $ this ->getCachedConnectionFactory ()], $ services ),
86+ containerOrAvailableServices: array_merge ([AmqpConnectionFactory::class => $ this ->getCachedConnectionFactory ($ amqpConfig )], $ services ),
6587 configuration: ServiceConfiguration::createWithDefaults ()
6688 ->withEnvironment ('prod ' )
6789 ->withSkippedModulePackageNames (ModulePackageList::allPackagesExcept ([ModulePackageList::AMQP_PACKAGE , ModulePackageList::ASYNCHRONOUS_PACKAGE ]))
0 commit comments