Azure / durabletask

Durable Task Framework allows users to write long running persistent workflows in C# using the async/await capabilities.
Apache License 2.0
1.51k stars 289 forks source link

ExtensionData in OrchestrationInstanceEx can share between OrchestrationDispatcherMiddleware but not ActivityDispatcherMiddleware #622

Open ChenglongLiu opened 2 years ago

ChenglongLiu commented 2 years ago

According #503, I think we can share session data between Orchestration and Activity. But my test did not meet expectations. My expected result is customInstance in every middle can share the Dic data. The test project is here .

`

            taskHub.AddOrchestrationDispatcherMiddleware(async (context, next) =>
            {
                OrchestrationRuntimeState runtimeState = context.GetProperty<OrchestrationRuntimeState>();
                var customInstance = OrchestrationInstanceEx.Initialize(runtimeState);
                customInstance.Dic["a"] = "a";
                customInstance.Dic["b"] = "b";
                customInstance.Dic["c"] = "c";
                context.SetProperty<OrchestrationInstance>(customInstance);
                await next();
            });

            taskHub.AddOrchestrationDispatcherMiddleware(async (context, next) =>
            {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                var customInstance = OrchestrationInstanceEx.Get(context.GetProperty<OrchestrationInstance>());
                context.SetProperty<OrchestrationInstance>(customInstance);

                //Dic data can get here. But missed in HelloOrchestration context and ActivityDispatcherMiddleware

                await next();
            });

            taskHub.AddActivityDispatcherMiddleware(async (context, next) =>
            {
                var customInstance = OrchestrationInstanceEx.Get(context.GetProperty<OrchestrationInstance>());
                context.SetProperty<OrchestrationInstance>(customInstance);

                //Dic data can missed here

                await next();
            });

`

jundayin commented 2 years ago

Do you eventually make it working? If not, what did you do alternatively

ChenglongLiu commented 2 years ago

From my understanding, it's not supported to share data between OrchestrationDispatcherMiddleware and ActivityDispatcherMiddleware. Passing data as one parameter is a solution.