0
# Namespace Management
1
2
Comprehensive namespace lifecycle management including creation, configuration, monitoring, network security, and disaster recovery setup. Namespaces are the top-level containers for all Service Bus messaging entities and provide the security boundary for access control.
3
4
## Capabilities
5
6
### Namespace Lifecycle Operations
7
8
Create, retrieve, update, delete, and list Service Bus namespaces across subscriptions and resource groups.
9
10
```python { .api }
11
def list(self) -> ItemPaged[SBNamespace]:
12
"""List all namespaces in the subscription."""
13
14
def list_by_resource_group(self, resource_group_name: str) -> ItemPaged[SBNamespace]:
15
"""List namespaces in a specific resource group.
16
17
Args:
18
resource_group_name (str): Name of the resource group.
19
20
Returns:
21
ItemPaged[SBNamespace]: Iterable of namespace resources.
22
"""
23
24
def begin_create_or_update(
25
self,
26
resource_group_name: str,
27
namespace_name: str,
28
parameters: SBNamespace
29
) -> LROPoller[SBNamespace]:
30
"""Create or update a Service Bus namespace.
31
32
Args:
33
resource_group_name (str): Name of the resource group.
34
namespace_name (str): Name of the namespace.
35
parameters (SBNamespace): Namespace configuration parameters.
36
37
Returns:
38
LROPoller[SBNamespace]: A poller for the long-running operation.
39
"""
40
41
def get(self, resource_group_name: str, namespace_name: str) -> SBNamespace:
42
"""Get details of a specific namespace.
43
44
Args:
45
resource_group_name (str): Name of the resource group.
46
namespace_name (str): Name of the namespace.
47
48
Returns:
49
SBNamespace: The namespace resource.
50
"""
51
52
def begin_delete(
53
self,
54
resource_group_name: str,
55
namespace_name: str
56
) -> LROPoller[None]:
57
"""Delete a namespace (long-running operation).
58
59
Args:
60
resource_group_name (str): Name of the resource group.
61
namespace_name (str): Name of the namespace.
62
63
Returns:
64
LROPoller[None]: Long-running operation poller.
65
"""
66
67
def update(
68
self,
69
resource_group_name: str,
70
namespace_name: str,
71
parameters: SBNamespaceUpdateParameters
72
) -> SBNamespace:
73
"""Update namespace properties.
74
75
Args:
76
resource_group_name (str): Name of the resource group.
77
namespace_name (str): Name of the namespace.
78
parameters (SBNamespaceUpdateParameters): Update parameters.
79
80
Returns:
81
SBNamespace: The updated namespace.
82
"""
83
```
84
85
### Name Availability Checking
86
87
Verify namespace name availability before creation to prevent conflicts.
88
89
```python { .api }
90
def check_name_availability(
91
self,
92
parameters: CheckNameAvailability
93
) -> CheckNameAvailabilityResult:
94
"""Check if a namespace name is available.
95
96
Args:
97
parameters (CheckNameAvailability): Name availability check request.
98
99
Returns:
100
CheckNameAvailabilityResult: Availability result with reason if unavailable.
101
"""
102
```
103
104
### Authorization Rule Management
105
106
Manage shared access signature (SAS) authorization rules for namespace-level access control.
107
108
```python { .api }
109
def list_authorization_rules(
110
self,
111
resource_group_name: str,
112
namespace_name: str
113
) -> ItemPaged[SBAuthorizationRule]:
114
"""List authorization rules for the namespace.
115
116
Args:
117
resource_group_name (str): Name of the resource group.
118
namespace_name (str): Name of the namespace.
119
120
Returns:
121
ItemPaged[SBAuthorizationRule]: Iterable of authorization rules.
122
"""
123
124
def create_or_update_authorization_rule(
125
self,
126
resource_group_name: str,
127
namespace_name: str,
128
authorization_rule_name: str,
129
parameters: SBAuthorizationRule
130
) -> SBAuthorizationRule:
131
"""Create or update an authorization rule.
132
133
Args:
134
resource_group_name (str): Name of the resource group.
135
namespace_name (str): Name of the namespace.
136
authorization_rule_name (str): Name of the authorization rule.
137
parameters (SBAuthorizationRule): Authorization rule parameters.
138
139
Returns:
140
SBAuthorizationRule: The created or updated authorization rule.
141
"""
142
143
def get_authorization_rule(
144
self,
145
resource_group_name: str,
146
namespace_name: str,
147
authorization_rule_name: str
148
) -> SBAuthorizationRule:
149
"""Get an authorization rule.
150
151
Args:
152
resource_group_name (str): Name of the resource group.
153
namespace_name (str): Name of the namespace.
154
authorization_rule_name (str): Name of the authorization rule.
155
156
Returns:
157
SBAuthorizationRule: The authorization rule.
158
"""
159
160
def delete_authorization_rule(
161
self,
162
resource_group_name: str,
163
namespace_name: str,
164
authorization_rule_name: str
165
) -> None:
166
"""Delete an authorization rule.
167
168
Args:
169
resource_group_name (str): Name of the resource group.
170
namespace_name (str): Name of the namespace.
171
authorization_rule_name (str): Name of the authorization rule.
172
"""
173
```
174
175
### Access Key Management
176
177
Generate and manage access keys for namespace authentication.
178
179
```python { .api }
180
def list_keys(
181
self,
182
resource_group_name: str,
183
namespace_name: str,
184
authorization_rule_name: str
185
) -> AccessKeys:
186
"""Get access keys for an authorization rule.
187
188
Args:
189
resource_group_name (str): Name of the resource group.
190
namespace_name (str): Name of the namespace.
191
authorization_rule_name (str): Name of the authorization rule.
192
193
Returns:
194
AccessKeys: Primary and secondary keys with connection strings.
195
"""
196
197
def regenerate_keys(
198
self,
199
resource_group_name: str,
200
namespace_name: str,
201
authorization_rule_name: str,
202
parameters: RegenerateAccessKeyParameters
203
) -> AccessKeys:
204
"""Regenerate access keys for an authorization rule.
205
206
Args:
207
resource_group_name (str): Name of the resource group.
208
namespace_name (str): Name of the namespace.
209
authorization_rule_name (str): Name of the authorization rule.
210
parameters (RegenerateAccessKeyParameters): Regeneration parameters.
211
212
Returns:
213
AccessKeys: New keys with connection strings.
214
"""
215
```
216
217
### Network Security Configuration
218
219
Configure network access rules, IP filtering, and virtual network integration.
220
221
```python { .api }
222
def create_or_update_network_rule_set(
223
self,
224
resource_group_name: str,
225
namespace_name: str,
226
parameters: NetworkRuleSet
227
) -> NetworkRuleSet:
228
"""Create or update network rule set for the namespace.
229
230
Args:
231
resource_group_name (str): Name of the resource group.
232
namespace_name (str): Name of the namespace.
233
parameters (NetworkRuleSet): Network rule configuration.
234
235
Returns:
236
NetworkRuleSet: The network rule set.
237
"""
238
239
def get_network_rule_set(
240
self,
241
resource_group_name: str,
242
namespace_name: str
243
) -> NetworkRuleSet:
244
"""Get network rule set for the namespace.
245
246
Args:
247
resource_group_name (str): Name of the resource group.
248
namespace_name (str): Name of the namespace.
249
250
Returns:
251
NetworkRuleSet: The current network rule set.
252
"""
253
254
def list_network_rule_sets(
255
self,
256
resource_group_name: str,
257
namespace_name: str
258
) -> ItemPaged[NetworkRuleSet]:
259
"""Gets list of NetworkRuleSet for a Namespace.
260
261
Args:
262
resource_group_name (str): Name of the resource group.
263
namespace_name (str): Name of the namespace.
264
265
Returns:
266
ItemPaged[NetworkRuleSet]: An iterator of network rule sets.
267
"""
268
```
269
270
## Usage Examples
271
272
### Creating a Basic Namespace
273
274
```python
275
from azure.mgmt.servicebus import ServiceBusManagementClient
276
from azure.mgmt.servicebus.models import SBNamespace, SBSku
277
from azure.identity import DefaultAzureCredential
278
279
client = ServiceBusManagementClient(DefaultAzureCredential(), subscription_id)
280
281
# Create a Standard tier namespace
282
namespace_params = SBNamespace(
283
location="East US",
284
sku=SBSku(
285
name="Standard",
286
tier="Standard"
287
),
288
tags={"environment": "production", "team": "messaging"}
289
)
290
291
namespace_operation = client.namespaces.begin_create_or_update(
292
resource_group_name="my-resource-group",
293
namespace_name="my-servicebus-namespace",
294
parameters=namespace_params
295
)
296
297
# Wait for the operation to complete
298
namespace = namespace_operation.result()
299
300
print(f"Namespace created: {namespace.name}")
301
print(f"Service Bus endpoint: {namespace.service_bus_endpoint}")
302
```
303
304
### Creating a Premium Namespace with Zone Redundancy
305
306
```python
307
# Create a Premium tier namespace with zone redundancy
308
premium_params = SBNamespace(
309
location="East US",
310
sku=SBSku(
311
name="Premium",
312
tier="Premium",
313
capacity=1 # 1, 2, or 4 messaging units
314
),
315
zone_redundant=True,
316
tags={"environment": "production", "tier": "premium"}
317
)
318
319
premium_namespace_operation = client.namespaces.begin_create_or_update(
320
resource_group_name="my-resource-group",
321
namespace_name="my-premium-namespace",
322
parameters=premium_params
323
)
324
325
# Wait for the operation to complete
326
premium_namespace = premium_namespace_operation.result()
327
```
328
329
### Creating Authorization Rules
330
331
```python
332
from azure.mgmt.servicebus.models import SBAuthorizationRule, AccessRights
333
334
# Create a send-only authorization rule
335
send_rule = SBAuthorizationRule(
336
rights=[AccessRights.SEND]
337
)
338
339
auth_rule = client.namespaces.create_or_update_authorization_rule(
340
resource_group_name="my-resource-group",
341
namespace_name="my-servicebus-namespace",
342
authorization_rule_name="SendOnlyPolicy",
343
parameters=send_rule
344
)
345
346
# Get the access keys
347
keys = client.namespaces.list_keys(
348
resource_group_name="my-resource-group",
349
namespace_name="my-servicebus-namespace",
350
authorization_rule_name="SendOnlyPolicy"
351
)
352
353
print(f"Primary connection string: {keys.primary_connection_string}")
354
```
355
356
### Checking Name Availability
357
358
```python
359
from azure.mgmt.servicebus.models import CheckNameAvailability
360
361
# Check if a namespace name is available
362
check_params = CheckNameAvailability(name="my-unique-namespace")
363
result = client.namespaces.check_name_availability(check_params)
364
365
if result.name_available:
366
print("Namespace name is available")
367
else:
368
print(f"Name unavailable: {result.reason} - {result.message}")
369
```
370
371
## Types
372
373
```python { .api }
374
class SBNamespace:
375
def __init__(self, **kwargs): ...
376
377
# Standard Azure resource properties
378
id: Optional[str]
379
name: Optional[str]
380
type: Optional[str]
381
location: Optional[str]
382
tags: Optional[Dict[str, str]]
383
384
# Service Bus specific properties
385
sku: Optional[SBSku]
386
identity: Optional[Identity]
387
provisioning_state: Optional[str]
388
status: Optional[str]
389
created_at: Optional[datetime]
390
updated_at: Optional[datetime]
391
service_bus_endpoint: Optional[str]
392
zone_redundant: Optional[bool]
393
encryption: Optional[Encryption]
394
private_endpoint_connections: Optional[List[PrivateEndpointConnection]]
395
disable_local_auth: Optional[bool]
396
alternate_name: Optional[str]
397
398
class SBNamespaceUpdateParameters:
399
def __init__(self, **kwargs): ...
400
401
location: Optional[str]
402
tags: Optional[Dict[str, str]]
403
sku: Optional[SBSku]
404
identity: Optional[Identity]
405
encryption: Optional[Encryption]
406
disable_local_auth: Optional[bool]
407
alternate_name: Optional[str]
408
409
class CheckNameAvailability:
410
def __init__(self, **kwargs): ...
411
412
name: str
413
414
class CheckNameAvailabilityResult:
415
def __init__(self, **kwargs): ...
416
417
message: Optional[str]
418
name_available: Optional[bool]
419
reason: Optional[Union[str, UnavailableReason]]
420
421
class UnavailableReason(str, Enum):
422
NONE = "None"
423
INVALID_NAME = "InvalidName"
424
SUBSCRIPTION_IS_DISABLED = "SubscriptionIsDisabled"
425
NAME_IN_USE = "NameInUse"
426
NAME_IN_LOCKDOWN = "NameInLockdown"
427
TOO_MANY_NAMESPACE_IN_CURRENT_SUBSCRIPTION = "TooManyNamespaceInCurrentSubscription"
428
429
class NetworkRuleSet:
430
def __init__(self, **kwargs): ...
431
432
trusted_service_access_enabled: Optional[bool]
433
default_action: Optional[Union[str, DefaultAction]]
434
virtual_network_rules: Optional[List[NWRuleSetVirtualNetworkRules]]
435
ip_rules: Optional[List[NWRuleSetIpRules]]
436
437
class RegenerateAccessKeyParameters:
438
def __init__(self, **kwargs): ...
439
440
key_type: Union[str, KeyType] # "PrimaryKey" or "SecondaryKey"
441
key: Optional[str]
442
443
class KeyType(str, Enum):
444
PRIMARY_KEY = "PrimaryKey"
445
SECONDARY_KEY = "SecondaryKey"
446
```