Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Allow to handle any RuntimeExceptions occurring when delivering an InboxMessage #1496

Merged
merged 48 commits into from
Jan 3, 2023

Conversation

armiol
Copy link
Contributor

@armiol armiol commented Nov 24, 2022

This changeset addresses #1472 and brings other improvements into the codebase.

Failure of signal reception, and DeliveryMonitor to respond

InboxMessages which are processed in scope of each Delivery run, are eventually unpacked, and the respective signals are dispatched to their targets. In case a signal target is an Entity, it is possible that the signal reception does not go well for various reasons. In particular, an aggregate may have "broken" @Apply-er, making it impossible to load the aggregate state. Or, some other unexpected error may occur upon loading or storing an entity.

Previously, it was impossible to trace such failures of signal reception. And the InboxMessages causing the errors were left in their inboxes in TO_DELIVER status forever, being delivered over and over again — most likely with the same reception failure repeating.

Now, the Delivery API allows to subscribe for any failures which occur during the reception of each signal. Additionally, end-users may now choose the way to handle the reception failures in terms of action in respect to the InboxMessage of interest.

Out-of-the-box, there are two actions provided:

  • mark the InboxMessage as delivered — so that it does not block further delivery of messages;
  • repeat the dispatching of the InboxMessage. Please note, this is a synchronous and immediate action in terms of a delivery run.

Alternatively, end-users may implement their own way of handling the reception failure.

The corresponding functionality is provided via the API of DeliveryMonitor.

Here is a code sample:

public final class MarkFailureDelivered extends DeliveryMonitor {

    /**
     * In case the reception of the {@code InboxMessage} failed,
     * mark it as {@code DELIVERED} anyway.
     */
    @Override
    public FailedReception.Action onReceptionFailure(FailedReception reception) {

    	//// Error details are available as well:
        // InboxMessage msg = reception.message();
        // Error error = reception.error();
        // notifyOf(msg, error);

        return reception.markDelivered();
    }
}

// ...

// Plugging the monitor into the Delivery:

DeliveryMonitor monitor = new MarkFailureDelivered();

Delivery delivery = Delivery.newBuilder()
        .setMonitor(monitor)
        // ...
        .build();

ServerEnvironment
        .when(MyEnvironment.class)
        .use(delivery);

By default, InboxMessages are marked as DELIVERED in case of failure of their reception. This is so, because otherwise the issue described in #1472 arises.

Internally, such a functionality became possible by making MessageDispatcher.dispatch(envelope) to return DispatchOutcome. Previously, it was void, which was not suitable for handling any of the issues synchronously — as it was required for InboxMessage to allow users choose the way to handle the reception failures.

Other changes

It was reported, that at run-time the routing of events by their interfaces may lead to ConcurrentModificationException.
This PR addresses the issue for v1 by making the Map of signal routes concurrency-friendly. See io.spine.server.route.MessageRouting for more details.

Even more minor changes are made to fix typos and remove the unused code.

The library version is set to 1.9.0-SNAPSHOT.6.

@armiol armiol self-assigned this Nov 24, 2022
@armiol armiol changed the base branch from master to 1.x-dev November 24, 2022 13:33
…llow the `DeliveryMonitor` instances access to more details.
… it could be used to diagnose any reception failures in scope of `Delivery` (in progress).
…ses in which there were no targets to route.
…ough endpoints into erroneous `DispatchOutcome`s.
@armiol armiol marked this pull request as ready for review January 2, 2023 16:23
Copy link
Contributor

@alexander-yevsyukov alexander-yevsyukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments and questions.

@armiol
Copy link
Contributor Author

armiol commented Jan 3, 2023

@alexander-yevsyukov PTAL again.

Copy link
Contributor

@alexander-yevsyukov alexander-yevsyukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@armiol armiol merged commit 37781a5 into 1.x-dev Jan 3, 2023
@armiol armiol deleted the 1x-delivery-reporting-errors branch January 3, 2023 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants