Azure Service Bus セッションを使用すると、関連するメッセージの無制限シーケンスを共同で順序付けして処理できます。 セッションは、先入れ先出し (FIFO) と 要求応答 のパターンで使用できます。 詳細については、「 メッセージ セッション」を参照してください。 この記事では、Service Bus キューまたはサブスクリプションのセッションを有効にするさまざまな方法について説明します。
Important
- Service Bus の Basic レベルはセッションをサポートしていません。 Standard レベルと Premium レベルでは、セッションがサポートされます。 これらのレベルの違いについては、「Service Bus の価格」を参照してください。
- キューまたはサブスクリプションの作成後にメッセージ セッションを有効または無効にすることはできません。 これは、キューまたはサブスクリプションの作成時にのみ実行できます。
Azure portal を使用
Azure portal で キュー を作成する場合は、次の図に示すように [セッションを有効にする] を選択します。
Azure portal でトピックのサブスクリプションを作成する場合は、次の図に示すように [セッションを有効にする] を選択します。
Azure CLI の使用
メッセージ セッションが有効になっているキューを作成するには、az servicebus queue create コマンドを使用し、--enable-sessionを true に設定します。
az servicebus queue create \
--resource-group myresourcegroup \
--namespace-name mynamespace \
--name myqueue \
--enable-session true
メッセージ セッションが有効になっているトピックのサブスクリプションを作成するには、az servicebus topic subscription createが --enable-session に設定された true コマンドを使用します。
az servicebus topic subscription create \
--resource-group myresourcegroup \
--namespace-name mynamespace \
--topic-name mytopic \
--name mysubscription \
--enable-session true
Azure PowerShell の使用
メッセージ セッションが有効になっているキューを作成するには、New-AzServiceBusQueue コマンドを使用し、-RequiresSessionを $True に設定します。
New-AzServiceBusQueue -ResourceGroup myresourcegroup `
-NamespaceName mynamespace `
-QueueName myqueue `
-RequiresSession $True
メッセージ セッションが有効になっているトピックのサブスクリプションを作成するには、New-AzServiceBusSubscriptionが -RequiresSession に設定された true コマンドを使用します。
New-AzServiceBusSubscription -ResourceGroup myresourcegroup `
-NamespaceName mynamespace `
-TopicName mytopic `
-SubscriptionName mysubscription `
-RequiresSession $True
テンプレートの使用
メッセージ セッションが有効になっているキューを作成するには、[キューのプロパティ] セクションでrequiresSessionをtrueに設定します。 詳細については、 Microsoft.ServiceBus 名前空間/キュー テンプレート リファレンスを参照してください。
@description('Name of the Service Bus namespace')
param serviceBusNamespaceName string
@description('Name of the Queue')
param serviceBusQueueName string
@description('Location for all resources.')
param location string = resourceGroup().location
resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2024-01-01' = {
name: serviceBusNamespaceName
location: location
sku: {
name: 'Standard'
}
resource queue 'queues' = {
name: serviceBusQueueName
properties: {
requiresSession: true
}
}
}
メッセージ セッションが有効になっているトピックのサブスクリプションを作成するには、[サブスクリプションのプロパティ] セクションでrequiresSessionをtrueに設定します。 詳細については、 Microsoft.ServiceBus 名前空間/トピック/サブスクリプション テンプレート リファレンスを参照してください。
@description('Name of the Service Bus namespace')
param serviceBusNamespaceName string
@description('Name of the Topic')
param serviceBusTopicName string
@description('Name of the Subscription')
param serviceBusSubscriptionName string
@description('Location for all resources.')
param location string = resourceGroup().location
resource serviceBusNamespace 'Microsoft.ServiceBus/namespaces@2024-01-01' = {
name: serviceBusNamespaceName
location: location
sku: {
name: 'Standard'
}
resource topic 'topics' = {
name: serviceBusTopicName
properties: {
maxSizeInMegabytes: 1024
}
resource subscription 'subscriptions' = {
name: serviceBusSubscriptionName
properties: {
requiresSession: true
}
}
}
}
次のステップ
Azure Service Bus の機能については、使用する言語のサンプルを試してみてください。
- .NET 用 Azure Service Bus クライアント ライブラリのサンプル (最新)
- Java 用 Azure Service Bus クライアント ライブラリのサンプル (最新)
- Python 用 Azure Service Bus クライアント ライブラリのサンプル
- JavaScript 用の Azure Service Bus クライアント ライブラリのサンプル
- TypeScript 用の Azure Service Bus クライアント ライブラリのサンプル
以前の .NET および Java クライアント ライブラリのサンプルを次に示します。
- .NET 用の Azure Service Bus クライアント ライブラリのサンプル (レガシー)
- Java 用の Azure Service Bus クライアント ライブラリのサンプル (レガシー)
2026 年 9 月 30 日に、Azure SDK ガイドラインに準拠していない Azure Service Bus SDK ライブラリ WindowsAzure.ServiceBus、Microsoft.Azure.ServiceBus、および com.microsoft.azure.servicebus は廃止されます。 SBMP プロトコルのサポートも終了するため、2026 年 9 月 30 日以降はこのプロトコルを使用できなくなります。 この日付より前に、重要なセキュリティ更新プログラムと強化された機能が提供される、最新の Azure SDK ライブラリに移行してください。
古いライブラリは 2026 年 9 月 30 日以降も引き続き使用できますが、Microsoft から公式のサポートと更新プログラムは提供されなくなります。 詳細については、サポート廃止のお知らせに関するページを参照してください。