Class InterceptorUtil
java.lang.Object
io.camunda.zeebe.gateway.interceptors.InterceptorUtil
A set of utilities which interceptor authors can use in their interceptors.
-
Method Details
-
getQueryApiKey
Returns an instance ofQueryApiusable in an interceptor. Note that, as per the gRPC documentation, it's perfectly fine to block in a call and/or listener, which may greatly simplify the usage of the API in your code.If you use the API asynchronously, there are a few gotchas to remember:
- if your interceptor is loaded via an external JAR, and it uses directly or indirectly the
Thread.getContextClassLoader()to load classes, you will need to make sure to set the appropriate context class loader in your callbacks, otherwise you may run intoClassNotFoundExceptionerrors - your callback may be executed on a different thread than the initial call, so you will
have to deal with thread safety; using a
SerializingExecutoror similar may help - since your callback may be executed on a different thread, the
Context.current()maybe different; if you want to use the same original context, you will need to close on it in your callback, or extract what you need from it beforehand and close on that
Example usage:
final Context context = Context.current(); final QueryApi api = InterceptorUtil.getQueryApiKey().get(context); final String processId; try { processId = queryApi.getBpmnProcessIdForProcess(processKey).toCompletableFuture().join(); } catch(final Exception e) { // close the call on error return; } // do something with the processId- Returns:
- the context key associated with the current query API
- if your interceptor is loaded via an external JAR, and it uses directly or indirectly the
-