DMN embedded Java


#1

I am using the Camunda DMN from Java and I made one simple test using a Decision Table with 3 lines. The response with 50 executions was 50 seconds and I would like to know how to improve the response time. Any suggestion?

DiagramaTeste.dmn (1.8 KB)


#2

Hi @Rudson_Rodrigues,

how do you evaluate the decisions? Can you share your code?

In general, the Camunda DMN engine is fast. Depends how you use it, it can evaluate more than 300.000 decision tables per second.
Please have a look at the blog post.

Best regards,
Philipp


#3

Hi, thanks for the answer.
Here is one of the implementations we are using, with just 3 rules to be evaluated. I tryied to compare against the rest and the return were faster then the embedded that I am showing below.

public static void printUsage(String errorMessage, int exitCode) {
	System.err.println("Error: " + errorMessage);
	System.err.println("Usage: java -jar Imovel.jar contatosVistoria");
	System.exit(exitCode);
}

public static void main(String[] args) {

	validateInput(args);

	VariableMap variables = prepareVariableMap(args);

	// parse decision from resource input stream
	InputStream inputStream = Imovel.class.getResourceAsStream("DiagramaImovel.dmn");

	try {
		parseAndEvaluateDecision(variables, inputStream);

	} finally {
		try {
			inputStream.close();
		} catch (IOException e) {
		}
	}
}

protected static void validateInput(String[] args) {

	// parse arguments
	if (args.length != 1) {
		printUsage("Favor informar o parametro: strEtapa", 1);
	}

	String etapa = args[0];
	if (!ETAPAS.contains(etapa)) {
		printUsage("strEtapa precisa ser uma das opções: " + ETAPAS, 2);
	}

}

protected static VariableMap prepareVariableMap(String[] args) {

	String strEtapa = args[0];

	// prepare variables for decision evaluation
	VariableMap variables = Variables.putValue("strEtapa", strEtapa);

	return variables;
}

protected static void parseAndEvaluateDecision(VariableMap variables, InputStream inputStream) {

	// create a new default DMN engine
	DmnEngine dmnEngine = DmnEngineConfiguration.createDefaultDmnEngineConfiguration().buildEngine();

	DmnDecision decision = dmnEngine.parseDecision("imovel", inputStream);

	// evaluate decision - for a single output
	DmnDecisionTableResult result = dmnEngine.evaluateDecisionTable(decision, variables);

	// returns the first rule result
	DmnDecisionRuleResult porcentagem = result.getFirstResult();
	// print result
	System.out.println("Porcentagem: " + porcentagem.values() + "%");
}

}


#4

Hi @Rudson_Rodrigues,

as far as I can see, this code snipped evaluates the decision exactly once. If you run the snipped 50 times then it may take longer because every time, you build the DMN engine and parse the DMN decision table before you evaluate it.

Usually, you build the DMN engine and parse the DMN model only once.

Best regards,
Philipp


#5

Ok, but how can I generate one microservice the receive massive requests?
Do you have any example to expose the result via Rest?


#6

Why don’t you just use the Camunda distribution?

However, if you want to build your own microservice then you could use Spring Boot with the Camunda integration.

Best regards,
Philipp