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 の機能については、使用する言語のサンプルを試してみてください。