I'm currently working on a project, where I need to route incoming requests to a specific target. There are multiple attributes the requests have, that need to be combined to select the correct target and execute the correct manipulations on the request. e.g. a request of user 1 needs to be routed to our test environment while user 2 needs to be routed to the integration environment...
There are also some more complex conditions like. All requests of user 2 need to be routed to int but the requests to one specific part of the application should actually be routed to the test environment.
My first approach was based on the wording the customer used and the architect of the project wanted to have a more generic approach. We designed together an alternative using 2 types of "filters". Each filter has a name and when executed returns the name of the filter, that should be executed next. Also each filter has gets a map (key-value-pairs) as an input which it uses to read from or write to. The first type of filter allows branching, based on one or multiple keys from the map (basically a switch-case-statement). The second filter reads in a value from the map (optional), selects some information from the value using regex (optional), defines an output-format or value and assigns the result to a key in the map. This filter can have multiple of those actions.
Those filters can be defined in a database and are loaded and stored, so that a controller can easily find them by name. When the controller receives a new request it extracts the key-value-pairs to the map and executes the first filter. Then it executes the filter returned by the previous filter until it gets no filtername to execute next.
I'm not sure if there is an official pattern or best practices of an approach like the one designed by the project's architect and me and I didn't find one. So I wanted to ask for some input on that topic.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire