Reputation: 563
My microservice has a Rest endpoint (getLocationForCar()) where it accepts a Car DTO (as below) as it's input , has some business logic to find the car at a location and returns the Location DTO (as below).
class Car {
String carId;
String carName;
String carType;
String carModel;
String carMake;
}
class Location {
String locationId;
String locationType;
String locationAddress;
}
I want to move the business logic to BPMN and DMN. I am new to BPMN and DMN. I went through few tutorials of Camunda and thought this is how I could get this working with Camunda:
This approach has issues (I need help getting the following questions answered):
Using Camunda (third part library) seems like a overhead because Camunda runs on it's own server and bpmn, dmn are deployed on that, this would slow down my process. So I am leaning more towards JBPM (although i have no idea if i can achieve my requirement using any of these).
Upvotes: 2
Views: 1615
Reputation: 476
DMN is a good way to extract your business logic. Imho Camunda is the best lightweigt and free possibility to do that.
Here an example for you
org.camunda.bpm.dmn:camunda-engine-dmn
org.camunda.bpm.dmn:camunda-engine-dmn-bom
DmnEngine dmnEngine = DmnEngineConfiguration
.createDefaultDmnEngineConfiguration()
.buildEngine();
VariableMap variables = Variables
.putValue("carId", carId)
.putValue("carName", carName);
.putValue("carType", carType);
.putValue("carModel", carModel);
.putValue("carMake", carMake);
InputStream inputStream = CarDecider.class.getResourceAsStream("carDecisionFile.xml");
try {
DmnDecision decision = dmnEngine.parseDecision("decision", inputStream);
// evaluate decision
DmnDecisionTableResult result = dmnEngine.evaluateDecisionTable(decision, variables);
// print result
String desiredLocation = result.getSingleResult().getSingleEntry();
System.out.println("Decision: " + desiredLocation);
}
finally {
try {
inputStream.close();
}
catch (IOException e) {
System.err.println("Could not close stream: "+e.getMessage());
}
}
}
If you want to use more complex DMN diagrams, you can use Decision Requirements Graph (see: https://docs.camunda.org/manual/7.6/reference/dmn11/drg/). With Camunda you can have multiple output values, like you need it in your example. Moreover, you can use Extensions for Camunda, like Feel Scala, with that you can use functions in your DMN files. Furthermore you can write your own custom functions for DMN. With this approach you don't need to use Camunda Platform. Just with 2 dependencies you can move your logic to those DMN files. With Camunda Modeler you can upload dmn files: for example you can create a microservice that receives those files and saves them in a database. Your DmnEngine micro service will load that files and evaluate decision.
Upvotes: 2