# Creating a new namespace in Temporal

**URL:** https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478
**Category:** Community Support
**Tags:** namespace
**Created:** [August 17, 2020, 9:51pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478 "2020-08-17T21:51:22Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)
#### Post date: [August 17, 2020, 9:51pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/1 "2020-08-17T21:51:22Z")

</div>

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

Thanks,

Kasi

---

<div class="post-metadata">

### Author: ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)
#### Post date: [August 18, 2020, 3:55am UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/2 "2020-08-18T03:55:34Z")

</div>

[Here is](https://docs.temporal.io/docs/tctl#namespace-operation-examples) the relevant CLI documentation.

Programmatically it is done through [gRPC API](https://github.com/temporalio/api/blob/1b9e06b811dc75f17495e06f81a07ab7de648f2e/temporal/api/workflowservice/v1/service.proto#L48) exposed by the service.

In Java the generated gRPC client is accessible through WorkflowServiceStubs:

```java
    WorkflowServiceStubs service =
        WorkflowServiceStubs.newInstance(
            WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build());
    RegisterNamespaceRequest request =
        RegisterNamespaceRequest.newBuilder()
            .setName(NAMESPACE)
            .setWorkflowExecutionRetentionPeriod(Durations.fromDays(7))
            .build();
    service.blockingStub().registerNamespace(request);

```

In Go SDK you can use higher-level [NamespaceClient](https://github.com/temporalio/go-sdk/blob/00fb03096c85ee092304125c0054f2d78de377a8/client/client.go#L350):

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

```

---

<div class="post-metadata">

### Author: ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)
#### Post date: [August 18, 2020, 5:03pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/3 "2020-08-18T17:03:31Z")

</div>

> [@maxim](#):
>
> ```auto
> WorkflowServiceStubs service =
> WorkflowServiceStubs.newInstance(
> WorkflowServiceStubsOptions.newBuilder().setTarget(serviceAddress).build());
> RegisterNamespaceRequest request =
> RegisterNamespaceRequest.newBuilder()
> .setName(NAMESPACE)
> .setWorkflowExecutionRetentionPeriod(Durations.fromDays(7))
> .build();
> service.blockingStub().registerNamespace(request);
> 
> ```

Thanks a ton

---

<div class="post-metadata">

### Author: ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)
#### Post date: [August 18, 2020, 5:55pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/4 "2020-08-18T17:55:22Z")

</div>

Hey Max,

I am running into an issue trying to connect to remote temporal server using grpc API as above, I am seeing java.io.IOException: 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?

Thanks

---

<div class="post-metadata">

### Author: ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)
#### Post date: [August 18, 2020, 7:52pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/5 "2020-08-18T19:52:57Z")

</div>

I’m not sure how to troubleshoot connectivity issues in your environment. Try invoking health service endpoint. One option [is to use curl.](https://medium.com/google-cloud/grpc-with-curl-a65d879a18f7)

---

<div class="post-metadata">

### Author: ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)
#### Post date: [August 21, 2020, 9:03pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/6 "2020-08-21T21:03:03Z")

</div>

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(ClientCalls.java:244)  
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:225)  
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:142)  
at io.temporal.workflowservice.v1.WorkflowServiceGrpc$WorkflowServiceBlockingStub.registerNamespace(WorkflowServiceGrpc.java:2546)  
at io.temporal.samples.common.RegisterNamespace.main(RegisterNamespace.java:19)  
FAILED  
temporal sevrer : 0.28.0

---

<div class="post-metadata">

### Author: ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)
#### Post date: [August 21, 2020, 9:40pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/7 "2020-08-21T21:40:46Z")

</div>

tried with server 0.27 also did not work

---

<div class="post-metadata">

### Author: ![kasi](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kasi](https://community.temporal.io/u/kasi)
#### Post date: [August 21, 2020, 9:41pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/8 "2020-08-21T21:41:28Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Nitz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/nitz/32/1510_2.png) [@Nitz](https://community.temporal.io/u/Nitz)
#### Post date: [November 24, 2021, 12:36pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/9 "2021-11-24T12:36:26Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)
#### Post date: [November 24, 2021, 2:48pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/10 "2021-11-24T14:48:33Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![Nitz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/nitz/32/1510_2.png) [@Nitz](https://community.temporal.io/u/Nitz)
#### Post date: [November 25, 2021, 11:06am UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/11 "2021-11-25T11:06:07Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)
#### Post date: [November 25, 2021, 3:59pm UTC](https://community.temporal.io/t/creating-a-new-namespace-in-temporal/478/12 "2021-11-25T15:59:12Z")

</div>

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:

```auto
@EventListener
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:

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

```

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

```auto

WorkflowStub untypedStub = WorkflowStub.fromTyped(typedStub);

```
