feat(amqp): Allow configurable delay strategy for backed channel #616
+75
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat(Amqp): Allow custom DelayStrategy in AmqpBackedMessageChannel
This commit introduces the ability to provide a custom
DelayStrategyfor AMQP-backed message channels.The
AmqpBackedMessageChannelBuildernow includes awithDelayStrategymethod, which passes the strategy down to theAmqpOutboundChannelAdapter. This allows users to extend or modify the default delaying behavior.An integration test has been added to verify that the custom strategy is correctly wired and invoked.
Why is this change proposed?
Previously, the
AmqpOutboundChannelAdapterutilizedHeadersExchangeDelayStrategyas the standard implementation for message delaying.This change introduces a configurable way for users to provide their own
DelayStrategyimplementation, increasing the flexibility of the component. This is beneficial for scenarios requiring custom delay logic, such as integrating with specific AMQP delay plugins or implementing specific business rules for message redelivery.Description of Changes
packages/Amqp/src/AmqpOutboundChannelAdapter.phpThe constructor was updated to accept an optional
?DelayStrategy $delayStrategy = nullparameter. Thehandlemethod now utilizes this injecteddelayStrategyif provided, while maintainingHeadersExchangeDelayStrategyas the default behavior to ensure backward compatibility.packages/Amqp/src/AmqpOutboundChannelAdapterBuilder.phpA new fluent method,
withDelayStrategy(DelayStrategy $delayStrategy): self, was added to store the user-definedDelayStrategy. Thecompilemethod was updated to pass this strategy to theAmqpOutboundChannelAdapterdefinition.packages/Amqp/src/AmqpBackedMessageChannelBuilder.phpA new fluent method,
withDelayStrategy(\Enqueue\AmqpTools\DelayStrategy $delayStrategy): self, was added. This delegates the provided strategy to the underlyingAmqpOutboundChannelAdapterBuilder, completing the configuration chain.packages/Amqp/tests/Fixture/AmqpChannel/SpyDelayStrategy.php(New File)A helper class
SpyDelayStrategywas created for testing purposes. It implementsEnqueue\AmqpTools\DelayStrategyand tracks method invocations while delegating to the default strategy to ensure correct behavior during tests.packages/Amqp/tests/Integration/AmqpChannelAdapterTest.phpA new integration test
test_using_custom_delay_strategy_from_channel_builder()was added. It registers aSpyDelayStrategy, configures the channel to use it, and verifies that the custom strategy is correctly invoked within the Ecotone container.Pull Request Contribution Terms