Hey folks, I have another problem.
I’m trying to use ContextPropagator in order to pass some (context) parameters down to my workflows (and activities).
I found this in the test for java sdk (from another thread in this forum):
So i tried to implement this in my (micronaut) application:
I implemented a TestContextPropagator (exactly the same as the one in the test, just in separate file, not static).
I created a interface and test workflow class (same as the ones in test):
import com.jakala.jnext.poc.user.lib.temporal.workflow.JNextWorkflow;
import io.temporal.workflow.WorkflowInterface;
import io.temporal.workflow.WorkflowMethod;
import org.slf4j.MDC;
public class ContextPropagationWorkflow {
@WorkflowInterface
public interface TestWorkflow {
@WorkflowMethod
String workflow1(String input);
}
public static class ContextPropagationWorkflowImpl implements TestWorkflow, JNextWorkflow {
@Override
public String workflow1(String input) {
// The test value should be in the MDC
return MDC.get("test");
}
}
}
I register workflow into worker, and try to execute this code in a controller:
MDC.put("test", "testing123");
WorkflowOptions options =
WorkflowOptions.newBuilder()
.setTaskQueue(tasklist)
.setContextPropagators(Collections.singletonList(new TestContextPropagator()))
.build();
ContextPropagationWorkflow.TestWorkflow workflow = client.newWorkflowStub(ContextPropagationWorkflow.TestWorkflow.class, options);
String result = workflow.workflow1("input1");
The problem is that result is null (so the “test” key is not propagated to the workflow), the expected result is instead to have “testing123”.
I checked with debugger, I noticed that the method setCurrentContext(Object context) in TestContextPropagator is not called (the one that is suppose to “propagate” the MDC setting on workflow side), the getCurrentContext() instead is called.
Is this a bug in the Java SDK or am I doing something wrong?
Thanks
Andrea