Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest Fabric, Power BI, and SQL learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Azure Service Bus sessions enable joint and ordered handling of unbounded sequences of related messages. Sessions can be used in first in, first out (FIFO) and request-response patterns. For more information, See Message sessions. This article shows you different ways to enable sessions for a Service Bus queue or subscription.
Important
When creating a queue in the Azure portal, select Enable sessions as shown in the following image.
When creating a subscription for a topic in the Azure portal, select Enable sessions as shown in the following image.
To create a queue with message sessions enabled, use the az servicebus queue create
command with --enable-session
set to true
.
az servicebus queue create \
--resource-group myresourcegroup \
--namespace-name mynamespace \
--name myqueue \
--enable-session true
To create a subscription for a topic with message sessions enabled, use the az servicebus topic subscription create
command with --enable-session
set to true
.
az servicebus topic subscription create \
--resource-group myresourcegroup \
--namespace-name mynamespace \
--topic-name mytopic \
--name mysubscription \
--enable-session true
To create a queue with message sessions enabled, use the New-AzServiceBusQueue
command with -RequiresSession
set to $True
.
New-AzServiceBusQueue -ResourceGroup myresourcegroup `
-NamespaceName mynamespace `
-QueueName myqueue `
-RequiresSession $True
To create a subscription for a topic with message sessions enabled, use the New-AzServiceBusSubscription
command with -RequiresSession
set to true
.
New-AzServiceBusSubscription -ResourceGroup myresourcegroup `
-NamespaceName mynamespace `
-TopicName mytopic `
-SubscriptionName mysubscription `
-RequiresSession $True
To create a queue with message sessions enabled, set requiresSession
to true
in the queue properties section. For more information, see Microsoft.ServiceBus namespaces/queues template reference.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serviceBusNamespaceName": {
"type": "string",
"metadata": {
"description": "Name of the Service Bus namespace"
}
},
"serviceBusQueueName": {
"type": "string",
"metadata": {
"description": "Name of the Queue"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"resources": [
{
"type": "Microsoft.ServiceBus/namespaces",
"apiVersion": "2018-01-01-preview",
"name": "[parameters('serviceBusNamespaceName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {},
"resources": [
{
"type": "Queues",
"apiVersion": "2017-04-01",
"name": "[parameters('serviceBusQueueName')]",
"dependsOn": [
"[resourceId('Microsoft.ServiceBus/namespaces', parameters('serviceBusNamespaceName'))]"
],
"properties": {
"requiresSession": true
}
}
]
}
]
}
To create a subscription for a topic with message sessions enabled, set requiresSession
to true
in the subscription properties section. For more information, see Microsoft.ServiceBus namespaces/topics/subscriptions template reference.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"service_BusNamespace_Name": {
"type": "string",
"metadata": {
"description": "Name of the Service Bus namespace"
}
},
"serviceBusTopicName": {
"type": "string",
"metadata": {
"description": "Name of the Topic"
}
},
"serviceBusSubscriptionName": {
"type": "string",
"metadata": {
"description": "Name of the Subscription"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"resources": [
{
"apiVersion": "2018-01-01-preview",
"name": "[parameters('service_BusNamespace_Name')]",
"type": "Microsoft.ServiceBus/namespaces",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {},
"resources": [
{
"apiVersion": "2017-04-01",
"name": "[parameters('serviceBusTopicName')]",
"type": "topics",
"dependsOn": [
"[resourceId('Microsoft.ServiceBus/namespaces/', parameters('service_BusNamespace_Name'))]"
],
"properties": {
"maxSizeInMegabytes": 1024
},
"resources": [
{
"apiVersion": "2017-04-01",
"name": "[parameters('serviceBusSubscriptionName')]",
"type": "Subscriptions",
"dependsOn": [
"[parameters('serviceBusTopicName')]"
],
"properties": {
"requiresSession": true
}
}
]
}
]
}
]
}
Try the samples in the language of your choice to explore Azure Service Bus features.
Find samples for the older .NET and Java client libraries below:
On 30 September 2026, we'll retire the Azure Service Bus SDK libraries WindowsAzure.ServiceBus, Microsoft.Azure.ServiceBus, and com.microsoft.azure.servicebus, which don't conform to Azure SDK guidelines. We'll also end support of the SBMP protocol, so you'll no longer be able to use this protocol after 30 September 2026. Migrate to the latest Azure SDK libraries, which offer critical security updates and improved capabilities, before that date.
Although the older libraries can still be used beyond 30 September 2026, they'll no longer receive official support and updates from Microsoft. For more information, see the support retirement announcement.
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest Fabric, Power BI, and SQL learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Discover Azure message queues - Training
Learn how to integrate Azure Service Bus and Azure Queue storage in to your solution, and how to send and receive message by using .NET.