You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过TypeScript配置EventhubNamespace的TLS 1.2版本

配置Event Hub命名空间使用TLS 1.2

注意:Event Hub的TLS版本是在命名空间级别配置的,所有属于该命名空间的Event Hub都会继承这个TLS设置,无需单独为每个Event Hub配置。

一、创建新命名空间时启用TLS 1.2

修改EventhubNamespaceService.ts中的createNamespace方法,在createOrUpdate的请求参数中添加minimumTlsVersion字段,设置为"1.2":

import { EventHubManagementClient } from '@azure/arm-eventhub';
export default class EventhubNamespaceService {
  client: EventHubManagementClient;

  constructor(client: EventHubManagementClient) {
    this.client = client;
  }

  async createNamespace(
    resourcegroupName: string,
    name: string,
    maximumThroughputUnits: number = 5,
    isAutoInflateEnabled: boolean = true,
    location: string = 'westeurope',
  ): Promise<EventhubNamespace> {
    const resp = await this.client.namespaces.createOrUpdate(resourcegroupName, name, {
      maximumThroughputUnits,
      isAutoInflateEnabled,
      location,
      // 添加TLS版本配置
      minimumTlsVersion: "1.2"
    });

    return {
      id: resp.id!,
      name: resp.name!,
      isAutoInflateEnabled: resp.isAutoInflateEnabled,
      maximumThroughputUnits: resp.maximumThroughputUnits,
      resourceGroup: resourcegroupName,
    };
  }
}

二、升级现有命名空间到TLS 1.2

在EventhubNamespaceService.ts中新增一个方法,用于更新现有命名空间的TLS版本:

// 在EventhubNamespaceService类中添加以下方法
async updateNamespaceTlsVersion(
  resourcegroupName: string,
  namespaceName: string
): Promise<void> {
  // 先获取当前命名空间的配置
  const existingNamespace = await this.client.namespaces.get(resourcegroupName, namespaceName);
  
  // 保留原有配置,仅更新TLS版本
  await this.client.namespaces.createOrUpdate(resourcegroupName, namespaceName, {
    ...existingNamespace,
    minimumTlsVersion: "1.2"
  });
}

调用这个方法时,只需传入资源组名称和命名空间名称即可完成升级。

关键说明

  • minimumTlsVersion的可选值包括"1.0"、"1.1"、"1.2",设置为"1.2"后,命名空间将拒绝使用TLS 1.0/1.1的连接请求。
  • 配置修改后立即生效,无需重启命名空间或Event Hub实例。
  • 所有现有连接会在下次重新连接时强制使用TLS 1.2,因此需要确保客户端已配置支持TLS 1.2。

内容的提问来源于stack exchange,提问作者yoyo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 22:07:36