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

How to split a large request into smaller ones, then returning a response by merging smaller responses, In PipelineBehavior #738

Closed
mjalil opened this issue Apr 19, 2022 · 4 comments

Comments

@mjalil
Copy link
Contributor

mjalil commented Apr 19, 2022

Hi,
I have a request like this:

public class TimeSerriesQuery 
{
    public DateTime From {get; set;}
    public DateTime To {get; set;}
}

and a response like this:

public class TimeSerries {
    public class DataPoint
    {
        public DateTime Time {get; set;}
        public double value {get; set;}
    }

    public DateTime LastTime {get; set;}
    public DataPoint[] DataPoints {get; set;}
}

I need to implement a IPipelineBehavior that split a TimeSerriesQuery with large time period into some queries with smaller time periods ,then send those requests to next handler in the pipeline, and then merge all small responses and return the final big response

I think the only possible way is to mutate the request to a smaller period and await on next, then mutate again and await again on next and do this until the whole period responses is ready, then merge them.
It seems it is not possible to call next multiple times concurrently with multiple split requests

How can I do that?

@mjalil mjalil changed the title In PipelineBehavior, I need to split a large request into smaller ones, then returning a response by merging smaller responses How to split a large request into smaller ones, then returning a response by merging smaller responses, In PipelineBehavior Apr 19, 2022
@jbogard
Copy link
Owner

jbogard commented Apr 19, 2022

You'd need to design your own solution inside a single PipelineBehavior. Delegate to some other interfaces and do this yourself. There's no out-of-the-box solution here.

The request exception actions/handlers are in a similar boat, that's why there's a separate interface for them and a behavior that coordinates calling into those separate behaviors.

@mjalil
Copy link
Contributor Author

mjalil commented Apr 20, 2022

Jimmy,

After your comment on request exception actions/handlers, I checked the source of exception actions/handlers to see some sample code. I've found a mistake and requested pull #739

Thank you

@KurogamiLight3303
Copy link

KurogamiLight3303 commented May 15, 2022

Hi, to solve the problem its not easy for you to create a handler for your TimeSerriesQuery that if the time periods is too large split the periods into smaller TimeSerriesQuery and then send it with
Task.WhenAll(_mediator.Send(subquery1), _mediator.Send(subquery2));,?

@mjalil
Copy link
Contributor Author

mjalil commented Aug 30, 2022

Task.WhenAll(_mediator.Send(subquery1), _mediator.Send(subquery2));

yes, that makes sense. thank you 👍

@mjalil mjalil closed this as completed Aug 30, 2022
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

No branches or pull requests

3 participants