mercredi 18 octobre 2017

Build Context (consumer client) specific spring application

I am building a spring-boot + grails application using grails 3.3.0 and spring-boot 1.5.6.RELEASE

I have controller serving JSON data to consumer client application.

ExampleController.groovy

class ExampleCotnroller {

    def endpointServerJosn(){
    }
}

Recently one more consumer was introduced and it expects the similar JSON data but from a different source.

So I added a flag to my application.yml another.client=true and modified my controller to:

Updated ExampleController.groovy

class ExampleCotnroller {

    def endpointServerJosn(){
        if(another.client){
            //server data from this client's source
        }else{
            //server data from other client's source
        }
    }
}

But I am expecting more set of clients and this going to mess up my controller as I don't find my solution scalable by design.

I was thinking of having an abstract controller like:

class AbstractApplicationController{

        def endpointServerJson();
}

class FirstCilentController extends AbstractApplicationController {
}

class SecondClientController extends AbstractApplicationController {
}

Is it possible to achieve a scalable solution with above design? Can application choose which controller to prefer based on config in external yml or application.yml file?

Aucun commentaire:

Enregistrer un commentaire