Skip to content

Conversation

@bakhritdinov
Copy link

feat(Amqp): Allow custom DelayStrategy in AmqpBackedMessageChannel

This commit introduces the ability to provide a custom DelayStrategy for AMQP-backed message channels.

The AmqpBackedMessageChannelBuilder now includes a withDelayStrategy method, which passes the strategy down to the AmqpOutboundChannelAdapter. 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 AmqpOutboundChannelAdapter utilized HeadersExchangeDelayStrategy as the standard implementation for message delaying.

This change introduces a configurable way for users to provide their own DelayStrategy implementation, 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.php
    The constructor was updated to accept an optional ?DelayStrategy $delayStrategy = null parameter. The handle method now utilizes this injected delayStrategy if provided, while maintaining HeadersExchangeDelayStrategy as the default behavior to ensure backward compatibility.

  • packages/Amqp/src/AmqpOutboundChannelAdapterBuilder.php
    A new fluent method, withDelayStrategy(DelayStrategy $delayStrategy): self, was added to store the user-defined DelayStrategy. The compile method was updated to pass this strategy to the AmqpOutboundChannelAdapter definition.

  • packages/Amqp/src/AmqpBackedMessageChannelBuilder.php
    A new fluent method, withDelayStrategy(\Enqueue\AmqpTools\DelayStrategy $delayStrategy): self, was added. This delegates the provided strategy to the underlying AmqpOutboundChannelAdapterBuilder, completing the configuration chain.

  • packages/Amqp/tests/Fixture/AmqpChannel/SpyDelayStrategy.php (New File)
    A helper class SpyDelayStrategy was created for testing purposes. It implements Enqueue\AmqpTools\DelayStrategy and tracks method invocations while delegating to the default strategy to ensure correct behavior during tests.

  • packages/Amqp/tests/Integration/AmqpChannelAdapterTest.php
    A new integration test test_using_custom_delay_strategy_from_channel_builder() was added. It registers a SpyDelayStrategy, configures the channel to use it, and verifies that the custom strategy is correctly invoked within the Ecotone container.

Pull Request Contribution Terms

  • I have read and agree to the contribution terms outlined in CONTRIBUTING.

This commit introduces the ability to provide a custom DelayStrategy for AMQP-backed message channels.

The AmqpBackedMessageChannelBuilder now has a withDelayStrategy method, which passes the strategy down to the AmqpOutboundChannelAdapter. This allows users to override the default delaying behavior.

An integration test has been added to verify that the custom strategy is correctly wired and invoked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant