Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multi namespace support #2378

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

Yogurt-lei
Copy link

@Yogurt-lei Yogurt-lei commented Jan 19, 2025

What was changed

The previous namespace is called RootNamespace.
A new configuration item named "temporal.namespaces" is added, and the configurations under it are all Non-rootNamespaces.
There are different workers and clients will register in different namespaces, and Activities and Workflows corresponding to a specific namespace can be discovered from different namespaces.

Why?

The current implementation only supports a single namespace.
In this PR, multi-namespaces support has been added.

Checklist

  1. Closes
    [Springboot] add support for multiple namespaces #1799
    SpringBoot - add @Primary to temporalWorkflowClient WorkflowClient Bean #1811

  2. How was this tested:

i. add new configuration

spring:
  temporal:
    connection:
      target: localhost
    start-workers: false
    namespaces:
      - namespace: assign
        alias: assign
        workers-auto-discovery:
          packages: com.component.temporal.assign
        workers:
          - task-queue: global
      - namespace: unassign
        alias: unassign
        workers-auto-discovery:
          packages: com.component.temporal.unassign
        workers:
          - task-queue: global

you can also define per-namespace specific bean.

// Note: TemporalOptionsCustomizer type bean must start with namespace/alias you defined. 
// And end with function class  name you want to customizer and concat Customizer as the bean name. 
// If we found none TemporalOptionsCustomizer defined. will give you a tips when you run the application.
  @Bean
    TemporalOptionsCustomizer<WorkflowServiceStubsOptions.Builder> assignWorkflowServiceStubsCustomizer() {
        return builder -> builder.setKeepAliveTime(Duration.ofHours(1));
    }

// also data converter is support
    @Bean
    DataConverter assignDataConverter() {
        return DataConverter.getDefaultInstance();
    }

ii. Wherever you want, we can inject the per-non-namespace bean via byName mode.

   // temporalWorkflowClient  this is the rootNamespace bean. 
    @Resource
    WorkflowClient workflowClient;

   // NOTE: bean name is corresponding namespace alias + ClassSimpleName
    @Resource(name = "assignWorkflowClient")
    private WorkflowClient assignWorkflowClient;

    @Resource(name = "unassignWorkflowClient")
    private WorkflowClient unassignWorkflowClient;

iii. Next, you can use beans from different namespaces anywhere.

  1. Any docs updates needed?

Signed-off-by: zhen.lei <yogurt_lei@foxmail.com>
@Yogurt-lei Yogurt-lei requested a review from a team as a code owner January 19, 2025 06:37
Copy link
Contributor

@Quinn-With-Two-Ns Quinn-With-Two-Ns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for opening this PR. Multi-namepace support is something we are interesting in adding. I left some comments on some other per namespace configurations we need.

Signed-off-by: zhen.lei <yogurt_lei@foxmail.com>
Signed-off-by: zhen.lei <yogurt_lei@foxmail.com>
Signed-off-by: zhen.lei <yogurt_lei@foxmail.com>
Signed-off-by: zhen.lei <yogurt_lei@foxmail.com>
Signed-off-by: zhen.lei <yogurt_lei@foxmail.com>
@Yogurt-lei
Copy link
Author

Yogurt-lei commented Jan 23, 2025

@Quinn-With-Two-Ns Add customizer and different connection by namespace.
@cretz Hope you still remeber this feature.
Let me know if we need more support for this feature.

Signed-off-by: zhen.lei <yogurt_lei@foxmail.com>
Signed-off-by: zhen.lei <yogurt_lei@foxmail.com>
@@ -70,6 +70,10 @@
*/
public interface DataConverter {

default boolean useInRootNamespace() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Dataconverter interface should not have any reference to springboot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data converter should follow the same principle as all the other per NS beans

@@ -80,21 +86,20 @@ public NamespaceTemplate rootNamespaceTemplate(
@Autowired(required = false) @Nullable Tracer otTracer,
@Qualifier("temporalTestWorkflowEnvironmentAdapter") @Autowired(required = false) @Nullable
TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
@Autowired(required = false) @Nullable
@Qualifier("temporalWorkerFactoryCustomizer") @Autowired(required = false) @Nullable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't adding this @Qualifier here filter break existing users since their TemporalOptionsCustomizer bean may not be named this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants