Search code examples
azureazure-data-factoryazureservicebushttp-status-code-401azure-servicebus-topics

Error HTTP 401 when trying to sent a message from Azure Data Factory to Service Bus


I have tried to reproduce Hugh Woods experiment (https://medium.com/asos-techblog/sending-messages-from-azure-data-factory-to-service-bus-86d4be6dd357) in my azure environment to sent messages from Azure DataFactory to Azure Service Bus.

I have followed the instructions, assigning the "Azure Service Bus Data Sender" role to my data factory’s managed identity.

But when I tried to sent a message to Service Bus I got this error:

Error code   : 2108
Failure type : User configuration issue
Details      : Invoking Web Activity failed with HttpStatusCode - 
               '401 : Unauthorized', message - ''
Source       : Pipeline Service Bus REST API

What am I doing wrong in this case? I have this configuration in my pipeline:

   {
    "name": "Service Bus REST API",
    "properties": {
        "activities": [
            {
                "name": "Service Bus REST API",
                "description": "Teste",
                "type": "WebActivity",
                "dependsOn": [],
                "policy": {
                    "timeout": "7.00:00:00",
                    "retry": 0,
                    "retryIntervalInSeconds": 30,
                    "secureOutput": false,
                    "secureInput": false
                },
                "userProperties": [],
                "typeProperties": {
                    "url": "https://sb-namespace-dv.servicebus.windows.net/sbt-azure-adf-ntt-data-test/messages",
                    "method": "POST",
                    "headers": {
                        "CustomHeader-Version": "\"1.0\"",
                        "Content-Type": "application/json",
                        "BrokerProperties": {
                            "value": "@concat('{\"CorrelationId\": \"',pipeline().RunId,'\"}')",
                            "type": "Expression"
                        }
                    },
                    "body": {
                        "value": "{\"message\":{\"value\":\"@variables('OutputDetails')\",\"type\":\"Expression\"}}",
                        "type": "Expression"
                    },
                    "httpRequestTimeout": "00:10:00",
                    "authentication": {
                        "type": "MSI",
                        "resource": "https://servicebus.azure.net"
                    }
                }
            }
        ],
        "folder": {
            "name": "999_Others/9910_DevTest/TesteServiceBusADF"
        },
        "annotations": []
    }
}

I have followed all steps of Hugh Woods article. I have expecting to get the same results of his experiment (below), but I did not have success.

{
message : "Snapshot Avaliable"
}

Solution

  • The message you are getting is HTTP 401 Unauthorized. So the call to write data to the service bus is being refused.

    There are 2 possibilities:

    • The authentication is not set up correctly
    • You tested it before the role assignments had propagated (can take 5 mins)

    See: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-managed-service-identity