none
Error "BadRequest" occurs when create a event hubs using c#

    Question

  • I'm using event hubs management libraries to create event hubs.

    when I set the destination to blob storage, the event hubs can be created successfully.

    But when I set the destination to azure data lake storage, the following error occurs: Microsoft.Azure.Management.EventHub.Models.ErrorResponseException: 'Operation returned an invalid status code 'BadRequest''. Btw, in azure portal, I can manually create event hubs with destination to the same azure data lake storage successfully.

    My code as below:

    static void Main(string[] args)
            {
                string tenantId = "xxxx";
                string clientId = "xxxx";
                string clientSecret = "xxxx";
                string subscriptionId = "xxxx";
                //string DataCenterLocation = "East US";
                string eventHubName = "xxxx";
                string resourceGroup = "xxxx";
                string nameSpace = "xxxx";


                var authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(string.Format("https://login.windows.net/{0}", tenantId));
                ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
                var result = authContext.AcquireTokenAsync("https://management.azure.com/", clientCred).GetAwaiter().GetResult();
                var accessToken = result.AccessToken;
                TokenCredentials creds = new TokenCredentials(accessToken);
                EventHubManagementClient client = new EventHubManagementClient(creds) { SubscriptionId = subscriptionId };

                Eventhub parameters = new Eventhub
                {
                    Status = EntityStatus.Active,
                    PartitionCount = 4,
                    MessageRetentionInDays = 4,
                    CaptureDescription = new CaptureDescription
                    {
                        IntervalInSeconds = 60,
                        SizeLimitInBytes = 10485760,
                        Enabled = true,
                        Encoding = EncodingCaptureDescription.Avro,
                        Destination = new Destination
                        {
                            Name = "EventHubArchive.AzureDataLake",
                            BlobContainer = "ss1",
                            StorageAccountResourceId = "/subscriptions/"+subscriptionId+"/resourceGroups/"+resourceGroup+ "/providers/Microsoft.DataLakeStore/accounts/my_azure_datalakeStorage",
                            ArchiveNameFormat = "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}"
                        }
                    }
                };

                var eventHub = client.EventHubs.CreateOrUpdate(resourceGroup, nameSpace, eventHubName, parameters);

                Console.WriteLine("--completed--");
                Console.ReadLine();
            }


    Friday, January 25, 2019 9:10 AM

All replies