---
title: "ウォークスルー:メッセージバスの役割をAzureサービスバスを使用する設定"
slug: "walkthrough--configuring-the-message-bus-role-to-use-azure-service-bus"
abstract: "Sitecoreメッセージバスの役割をAzureサービスバスで使用する設定方法。"
---
# ウォークスルー:メッセージバスの役割をAzureサービスバスを使用する設定

メッセージバスの役割をAzureサービスバスに設定する前に、まずAzureサービスバスをプロビジョニングし、プライマリ接続文字列を取得する必要があります。詳細は[Microsoftの「サービスバスを作成」というAzureポータル](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-create-namespace-portal) のドキュメントを参照してください。

このウォークスルーでは、以下の方法を説明します:

-   [メッセージング接続文字列を変更する](https://doc.sitecore.com/xp/ja/developers/92/platform-administration-and-architecture/walkthrough--configuring-the-message-bus-role-to-use-azure-service-bus.html#UUID-0035b38a-4695-e4c3-dce3-25e170ce3fc4_section-idm4525572914964831621252233593 "Change the messaging connection strings")
-   [メッセージングTransportキーを変更してください](https://doc.sitecore.com/xp/ja/developers/92/platform-administration-and-architecture/walkthrough--configuring-the-message-bus-role-to-use-azure-service-bus.html#UUID-0035b38a-4695-e4c3-dce3-25e170ce3fc4_section-idm4623774698768031621283559501 "Change the messagingTransport keys")
-   [メッセージング設定ファイルを切り替える](https://doc.sitecore.com/xp/ja/developers/92/platform-administration-and-architecture/walkthrough--configuring-the-message-bus-role-to-use-azure-service-bus.html#UUID-0035b38a-4695-e4c3-dce3-25e170ce3fc4_section-idm4616737386337631621297462216 "Switch the messaging configuration files")
-   [コンテナで使用するためにメッセージバスの役割を設定する](https://doc.sitecore.com/xp/ja/developers/92/platform-administration-and-architecture/walkthrough--configuring-the-message-bus-role-to-use-azure-service-bus.html#UUID-0035b38a-4695-e4c3-dce3-25e170ce3fc4_section-idm23206209965709 "Configure the Message Bus role for use with containers")

## メッセージング接続文字列を変更する

[メッセージバスの役割を参照](https://doc.sitecore.com/xp/ja/developers/92/platform-administration-and-architecture/message-bus.html "Message Bus")するすべてのロールで、messaging接続文字列を「Microsoft SQL Server」から「サービスバス」Azureに変更しなければなりません。

messaging接続文字列を変更するには:

1.  <wwwroot>\\App\_Config\\フォルダでConnectionStrings.configファイルを開いてください。
    
2.  add name="messaging"プロパティを見つけて、connectionString属性をAzure Service Bus接続文字列に変更します。
    
    <add
     name="messaging"
     connectionString="<your Azure Service Bus connection string>" />
    
3.  ConnectionStrings.configファイルを保存してください。
    
4.  関連の役割すべてで同じ手順を繰り返してください。
    

## メッセージングTransportキーを変更してください

メッセージバスの役割を参照するすべての[コアロール](https://doc.sitecore.com/xp/ja/developers/92/platform-administration-and-architecture/roles-overview.html "Roles overview")で、messagingTransportキーをMicrosoft SQL ServerからAzureメッセージバスに変更しなければなりません。

messagingTransportキーを変更するには:

1.  <wwwroot>\\フォルダでWeb.configファイルを開いてください。
    
2.  add key="messagingTransport:defineプロパティを見つけ、value属性をSQLからAzureServiceBusに変更します。
    
    <add key="messagingTransport:define" value="AzureServiceBus" />
    
3.  Web.configファイルを保存してください。
    
4.  関連の役割すべてで同じ手順を繰り返してください。
    

## メッセージング設定ファイルを切り替える

メッセージバス役割を参照するすべての[XPサービスロール](https://doc.sitecore.com/xp/ja/developers/92/platform-administration-and-architecture/roles-overview.html "Roles overview") で、すべてのメッセージング設定ファイルをMicrosoft SQL ServerからAzureに切り替える必要があります。設定ファイルは以下のフォルダにあります:

-   <wwwroot>\\App\_Data\\Config\\Sitecore\\ およびそのサブフォルダ
-   <wwwroot>\\App\_Data\\jobs\\continuous\\\*\\App\_Data\\Config\\sitecore\\ およびそのサブフォルダ

メッセージング設定ファイルを切り替えるには:

1.  すべてのファイルに .disabledの拡張子を追加してください。 \*Messaging.SqlServer.xml。
    
    \*Messaging.SqlServer.xml -> \*Messaging.SqlServer.xml.disabled
    
2.  \*Messaging.Azure.xml.disabledに一致するすべてのファイルから.disabled拡張子を削除してください。
    
    \*Messaging.Azure.xml.disabled -> \*Messaging.Azure.xml
    
3.  関連の役割すべてで同じ手順を繰り返してください。
    

## コンテナで使用するためにメッセージバスの役割を設定する

Sitecoreを導入するためにコンテナを使用している場合は、この追加手順を実行しなければなりません。

> !重要ここで示す手順とスクリプトは、Sitecoreのインストールに合わせて編集・調整できる例です。これらはサポートされておらず、あなたのインスピレーションを得るためのものです。

コンテナで使用するメッセージバスの役割を設定するには:

1.  docker-compose.yml[コンテナにデプロイする準備Sitecore。](https://containers.doc.sitecore.com/)
    
2.  メッセージングを使う各役割について:
    
    -   \*.ps1ファイルとDockerファイルが入っているフォルダで、このコマンドを実行して役割用の新しいDockerイメージを作成します:docker build --tag sitecore-<VERSION>-<ROLE NAME>-asb <PATH TO YOUR FOLDER>。
    -   docker-compose.ymlファイルでimage設定を${SITECORE\_DOCKER\_REGISTRY}sitecore-<VERSION>-XX:${SITECORE\_VERSION}からsitecore-<VERSION>-<ROLE NAME>-asbに変更してください。
3.  docker-compose.ymlファイルでSitecore\_ConnectionStrings\_MessagingをAzureメッセージバスのプライマリ接続文字列に変更してください(Endpoint=<XXX>;SharedAccessKeyName=<XXX>;SharedAccessKey=<XXX>)。
    
4.  enable-messaging-asb.ps1というファイルを作成し、以下の*スクリプトの例*を貼り付けPowerShell:
    
    Function Set-XmlAttribute(
     string$XmlFilePath,
     string$Xpath,
     string$AttributeName,
     string$Value)
    {
      Write-Host"Setting XML attribute $AttributeName with value $Value from $XmlFilePath using xPath $XPath"
      xml$XmlFile = Get-Content $XmlFilePath
      $Item = Select-XML -Xml $XmlFile -XPath $XPath
      if($Item -ne $null) {
        $node = $Item.node
        $Item | %{$\_.node.$AttributeName = $Value}
        $XmlFile.Save($XmlFilePath)
      } else {
        Write-Host "Node is not exist in $XmlFilePath, XPath: $XPath" -Level "Warning"
      }
    }
    
    Write-Host "Disabling \*Messaging.SqlServer.xml ..."
    Get-ChildItem -Path "." -Filter "\*Messaging.SqlServer.xml"  -Recurse | ForEach-Object {
      $newName = "$($\_.FullName).disabled";
      Write-Host $newName
      Move-Item -Path $\_.FullName -Destination $newName -Force
    }
    Write-Host "Disabling \*Messaging.SqlServer.xml done"
    
    Write-Host "Enabling \*Messaging.Azure.xml.disabled ..."
    Get-ChildItem -Path "." -Filter "\*Messaging.Azure.xml.disabled"  -Recurse | ForEach-Object {
      $newName = $\_.FullName.Substring(0, $\_.FullName.LastIndexOf(".disabled"));
      Write-Host $newName
      Move-Item -Path $\_.FullName -Destination $newName -Force
    }
    Write-Host "Enabling \*Messaging.Azure.config.disabled done"
    
    Write-Host "Updating Web.config"
    $currentFolder = Get-Location
    Set-XmlAttribute -XmlFilePath "$currentFolder\\Web.config" -xpath "//configuration/appSettings/add@key='messagingTransport:define'" -AttributeName "value" -Value "AzureServiceBus"
    Write-Host "Web.config is updated"
    
5.  以下の[Dockerファイル](https://docs.docker.com/engine/reference/builder/#arg)を実行します:
    
    FROM ${BASE\_IMAGE}
    COPY ./enable-messaging-asb.ps1 ./
    RUN .\\enable-messaging-asb.ps1
    
6.  イメージを展開してください。