错误“BadRequest”使用c#创建事件集线器时发生 [英] Error "BadRequest" occurs when create a event hubs using c#

查看:94
本文介绍了错误“BadRequest”使用c#创建事件集线器时发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用事件中心管理库来创建事件中心。





但是当我将目标设置为azure数据湖存储时,会发生以下错误:Microsoft.Azure.Management.EventHub.Models.ErrorResponseException:'Operation返回了无效的状态代码'BadRequest''。顺便说一句,在天蓝色的门户网站中,我可以手动
创建事件中心,并且成功地将目标连接到相同的azure数据湖存储。



我的代码如下:


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 =新Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(的String.Format(QUOT; HTTPS://login.windows.net/ {0}" ;, tenantId));

             ClientCredential clientCred = new ClientCredential(clientId,clientSecret);

            VAR结果= authContext.AcquireTokenAsync(QUOT; HTTPS://management.azure.com/" ;, clientCred).GetAwaiter()调用getResult();

    群组。 ;       var accessToken = result.AccessToken;

            TokenCredentials creds = new TokenCredentials(accessToken);

            EventHubManagementClient客户=新EventHubManagementClient(creds){SubscriptionId = subscriptionId};



             Eventhub parameters = new Eventhub

            {

                Status = EntityStatus.Active,

                PartitionCount = 4,

                MessageRetentionInDays = 4,

                CaptureDescription = new CaptureDescription

                {

                    IntervalInSeconds = 60,

                    SizeLimitInBytes = 10485760,

                   启用=真,

                   编码= EncodingCaptureDescription.Avro,

                    目的地=新目的地

                    {

                    &NBSP ;  名称= QUOT; EventHubArchive.AzureDataLake" ;,

                &NBSP ;       BlobContainer = QUOT; SS1" ;,

                 &NBSP ;      StorageAccountResourceId = QUOT; /订阅/" + subscriptionId + QUOT; / resourceGroups /" +资源组+
" /providers/Microsoft.DataLakeStore/accounts/my_azure_datalakeStorage" ;,

 &NBSP ;                      ArchiveNameFormat =" {Namespace} / {EventHub} / {PartitionId} / {Year} / {Month} / {Day} / {Hour} / {Minute} / {Second}"

  ;                   }
                }
            }


            VAR eventHub = client.EventHubs.CreateOrUpdate(资源组,命名空间eventHubName,参数);



             Console.WriteLine(" - completed - ");

            Console.ReadLine();

        }


解决方案

您使用的是Azure Data Lake Store V2吗? ADLS V2可与blob存储互操作。它是一个具有额外功能的专业Blob存储。使用V2,应该没有问题。


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();
        }

解决方案

Are you using Azure Data Lake Store V2 ? ADLS V2 is inter-operable with blob storage. Its a specialized Blob Storage with extra features. With V2, there should be no problem.


这篇关于错误“BadRequest”使用c#创建事件集线器时发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆