Creating a new namespace in Temporal

How do you do it in temporal, programmatically and from command line.



Here is the relevant CLI documentation.

Programmatically it is done through gRPC API exposed by the service.

In Java the generated gRPC client is accessible through WorkflowServiceStubs:

    WorkflowServiceStubs service =
    RegisterNamespaceRequest request =

In Go SDK you can use higher-level NamespaceClient:

	client, err := client.NewNamespaceClient(client.Options{HostPort: ts.config.ServiceAddr})
	err = client.Register(ctx, &workflowservice.RegisterNamespaceRequest{
		Name:                             name,
		WorkflowExecutionRetentionPeriod: &retention,


Thanks a ton

1 Like

Hey Max,

I am running into an issue trying to connect to remote temporal server using grpc API as above, I am seeing Connection reset by peer and when I run from docker i am seeing the following exception

Error: Operation DescribeNamespace failed.

Error Details: last connection error: connection error: desc = “transport: Error while dialing dial tcp: lookup xxxx:1234 on [::1]:53: read udp [::1]:45479->[::1]:53: read: connection refused”

nc to the temporal hostname:port succeeds from mac. Any ideas? do I need to set any other property for the gRpc to work?


I’m not sure how to troubleshoot connectivity issues in your environment. Try invoking health service endpoint. One option is to use curl.

I am seeing the following exception running above code to local server
RegisterNamespace.main()Exception in thread “main” io.grpc.StatusRuntimeException: UNIMPLEMENTED: unknown service temporal.workflowservice.v1.WorkflowService
at io.grpc.stub.ClientCalls.toStatusRuntimeException(
at io.grpc.stub.ClientCalls.getUnchecked(
at io.grpc.stub.ClientCalls.blockingUnaryCall(
at io.temporal.workflowservice.v1.WorkflowServiceGrpc$WorkflowServiceBlockingStub.registerNamespace(
at io.temporal.samples.common.RegisterNamespace.main(
temporal sevrer : 0.28.0

tried with server 0.27 also did not work

I am seeing this error when I am running the basic HelloActivity examples

How to start worker with multiple namespaces @maxim .
do we need separate serviceStub for each namespace?

You can have a single WorkflowServiceStubs instance, but you need a separate WorkflowClient instance for each namespace (and set the namespace via WorkflowClientOptions).

A worker is associated with a single namespace (as its WorkerFactory is tied to a single WorkflowClient instance).


Thanks @tihomir ,
I am using spring boot
for each namespace n:

  • create client // step 1
  • from this client create factory // step 2
  • start factory //step 3

Now when I want to invoke a workflow in a namespace , we create WorkflowStub like this :
WorkflowStub stub = workflowClient.newUntypedWorkflowStub(“xyzType”, options);

I will need exact same workflowClient that I had created above , step 1.
Is this correct?

You want to create your WorkflowServiceStubs, and all your WorkflowClient, and WorkerFactory one time only. There is probably multiple ways to do that but typically I’ve done that with event listener method in an application scoped bean, or your @SpringBootApplication, for example:

public void handleContextStartedEvent(ContextStartedEvent event) {
    // your code here....

For your workers, you can add them there as well, but note that in that case in order to restart a particular worker you would need to restart your whole app. Having a way to be able to restart your worker (in case you want to fix an error for example, or introduce some changes with versioning) would make more sense, without having to restart your whole app.

Yes, for each namespace you will need to create its own WorkflowClient, WorkerFactory and set of workers for that namespace.

Now when I want to invoke a workflow in a namespace , we create WorkflowStub like this :
WorkflowStub stub = workflowClient.newUntypedWorkflowStub(“xyzType”, options);

That’s the untyped approach. If in your application you have the workflow interface available you can use the typed approach, for example:

XyzWorkflow typedStub
        client.newWorkflowStub(XyzWorkflow.class, options);

note you can always convert from a typed to an untyped workflow stub, for example:

WorkflowStub untypedStub = WorkflowStub.fromTyped(typedStub);