
SeaTunnel AzureQueueStorage Sink 连接器三种认证模式、异步背压与投递语义详解【免费下载链接】seatunnelSeaTunnel is a multimodal, high-performance, distributed, massive data integration tool.项目地址: https://gitcode.com/GitHub_Trending/se/seatunnel在 SeaTunnel 中把每行数据“落地”到消息队列类目标时Azure Queue Storage 是一个轻量且稳定的选择。本篇基于官方文档 AzureQueueStorage.md 与连接器源码完整讲清该 sink 的全部配置项、三种认证路径的填写规则、异步发送的背压机制max_in_flight信号量、checkpoint/关闭时的冲刷逻辑以及 at-least-once 投递语义下的消费端注意事项。读完后你可以直接复制 HOCON 示例作业、正确选择认证方式并理解每条消息从序列化到发送的完整链路。连接器定位与引擎支持AzureQueueStorage 是一个sink 连接器将接收到的每一条 SeaTunnel 行SeaTunnelRow序列化为一条消息发布到指定的 Azure Storage 队列中。支持的执行引擎来自文档 Supported Engines 章节SparkFlinkSeaTunnel Zeta关键能力矩阵能力支持情况batch✅stream✅exactly-once❌cdc❌support multiple table write❌timer flush❌源码位于seatunnel-connectors-v2/connector-azure-queue-storage/模块sink 侧核心类为 AzureQueueStorageSink、AzureQueueStorageSinkWriter 与 AzureQueueStorageSinkFactory。注意该模块同时包含 source 侧实现source包本篇仅聚焦 sink。配置项总览Options以下参数表完整继承自官方文档 Options 章节取值与默认值已在 AzureQueueStorageSinkOptions 中逐一得到源码印证nametyperequireddefault valuequeue_namestringyes-authentication_typeenumyes-connection_stringstringconditional-endpointstringconditional-account_namestringconditional-account_keystringconditional-sas_tokenstringconditional-formatenumnojsonfield_delimiterstringno,message_encodingenumnononemax_in_flightintno100operation_timeout_mslongno60000common-optionsno-其中conditional的含义由authentication_type决定具体组合见下文。sink 公共参数如save_mode、sink_parallelism等请参考 Sink Common Options。目标队列queue_namequeue_name指定目标 Azure Storage 队列且队列必须在作业启动前已经存在——连接器不会自动建队列。命名规则在 AzureQueueConfigValidator 中用正则强制校验3–63 个字符仅允许小写字母、数字和单个连字符不允许连续双连字符首尾必须为字母或数字。对应源码中的模式private static final Pattern QUEUE_NAME_PATTERN Pattern.compile(a-z0-9?); // 另校验 length 在 3..63 之间且不含 --因此诸如Events含大写、ev-以连字符结尾、ev--ents双连字符都会在作业启动前的配置校验阶段直接报错。认证模式authentication_typeauthentication_type是必填枚举显式选择一条认证路径。三种模式各自的必填项如下且不同模式的凭据不允许混配authentication_type必填项禁止同时出现的项connection_stringconnection_stringendpoint、account_name、account_key、sas_tokenshared_keyendpoint、account_name、account_keyconnection_string、sas_tokensas_tokenendpoint、sas_tokenconnection_string、account_name、account_key这一“互斥”约束在 AzureQueueConfigValidator.validateClient 中通过requireNonBlank必须非空与rejectPresent必须缺席成对实现例如选择shared_key时connection_string与sas_token一旦被配置就会抛出Option connection_string is not valid for the selected authentication_type。同样的条件关系也声明在 AzureQueueStorageSinkFactory.optionRule 的OptionRule中用于连接器工厂层的必填/条件校验。各凭据参数的语义connection_stringAzure Storage 连接字符串。文档明确指出该模式也兼容 Azurite本地模拟存储的连接字符串即允许自定义QueueEndpoint方便本地开发联调。endpoint队列服务端点形如https://myaccount.queue.core.windows.net。account_name / account_key共享密钥认证使用的存储账户名与账户密钥。sas_tokenSAS 令牌。源码 AzureQueueClientFactory.normalizeSasToken 会去掉开头的?后再交给 SDK因此从完整 URL query 中复制出来的带?前缀令牌也可以直接使用。文档同时承诺连接器不会把凭据值写入日志。从源码结构看凭据最终由 AzureQueueClientFactory.builder 转交给 Azure SDK 的QueueClientBuilderconnection_string模式走builder.connectionString(...)shared_key模式用StorageSharedKeyCredential加 endpointsas_token模式用归一化后的 token 加 endpoint。消息内容format、field_delimiter 与 message_encodingformat 与 field_delimiterformat决定消息负载格式json默认将行序列化为 JSON 对象。text将行的各字段用field_delimiter拼接成文本默认分隔符为,。AzureQueueStorageSinkWriter.createSerializationSchema 中分别构造JsonSerializationSchema基于行类型SeaTunnelRowType或TextSerializationSchema使用配置的field_delimiter。AzureQueueSinkConfig.validate 还要求format text时field_delimiter不能为空字符串。message_encoding 与 64 KiB 消息上限message_encoding控制 Azure SDK 的消息编码none默认UTF-8 负载原样发送。base64发送前对 UTF-8 负载做 Base64 编码。Azure Queue Storage 对编码后的单条消息上限为 64 KiB。连接器在发送前主动校验大小见 AzureQueueStorageSinkWriter.validateMessageSizelong encodedSize payloadSize; if (messageEncoding MessageEncoding.BASE64) { encodedSize 4L * ((payloadSize 2L) / 3L); // Base64 膨胀系数 } if (encodedSize MAX_ENCODED_MESSAGE_BYTES) { // 64 * 1024 字节 throw new AzureQueueConnectorException(MESSAGE_TOO_LARGE, ...); }因此使用base64时序列化后的原始负载最大只能约 48 KiBBase64 会使体积膨胀约 4/3。超限会以MESSAGE_TOO_LARGE错误码在写入口即抛错而不是等 Azure 端拒绝。如果你的行数据可能接近该上限优先考虑jsonnone编码或在上游拆分大字段。并发与超时max_in_flight 和 operation_timeout_ms两个参数控制异步发送的节奏默认值分别为 100 与 60000且配置校验要求二者均必须大于 0见 AzureQueueSinkConfig.validate 与 OptionRule 中的Conditions.greaterThan。max_in_flight每个 sink task 允许“在途”已提交但未确认完成的异步发送上限。operation_timeout_ms等待可用发送槽位、或在 checkpoint/关闭时等待在途发送完成的最大时长。源码级实现信号量 在途任务集合AzureQueueStorageSinkWriter 用Semaphore(maxInFlight)实现背压write(row)的完整链路为先检查是否已有异步发送失败checkSendError失败会立即快速抛出序列化行并校验消息大小tryAcquire(operationTimeoutMillis, MILLISECONDS)获取发送许可——若在超时时间内拿不到槽位抛出“Timed out waiting for an available Azure Queue send slot”超时错误形成对上游的背压调用sender.send(message)底层为 Azure SDKQueueAsyncClient.sendMessage的异步响应见 AzureQueueStorageSender把返回的CompletableFuture记入pendingSends集合发送完成后无论成败释放许可、移出pendingSends失败则把异常写入sendError在下一个write或flush时向任务上报。prepareCommit()与close()都会先执行flush()对pendingSends中所有未完成任务调用CompletableFuture.allOf(...).get(operationTimeoutMillis, ...)等待其完成超时或失败都会转成AzureQueueConnectorException抛出。也就是说checkpoint 与正常关闭时连接器会等待所有已接受的发送落到队列——这是其投递语义的基础。交付语义Delivery Semantics文档对语义的表述明确值得逐条理解连接器在 checkpoint 和 shutdown 时等待所有已接受的发送并把异步失败上报给任务在途发送数量受max_in_flight约束从 SeaTunnel 作业视角看投递是 at-least-once客户端重试或任务恢复可能导致同一条消息被重复发布消费端必须容忍重复连接器不会创建队列、不会按行路由到不同队列、也不提供exactly-once 投递。设计上的取舍很清晰用异步 SDK 换取吞吐用 checkpoint 前的全量 flush 换取“不丢已确认接受的消息”而把幂等责任交给消费端。如果你的下游要求精确一次需要在消费侧基于消息内容或业务键做去重。任务示例Task Example以下三组 HOCON 配置完整继承自官方文档 Task Example 章节分别对应三种认证模式可直接复制到作业配置的sink {}块中模式一Connection Stringsink { AzureQueueStorage { queue_name events authentication_type connection_string connection_string DefaultEndpointsProtocolhttps;AccountNamemyaccount;AccountKey...;EndpointSuffixcore.windows.net format json } }模式二Shared Keysink { AzureQueueStorage { queue_name events authentication_type shared_key endpoint https://myaccount.queue.core.windows.net account_name myaccount account_key ... format text field_delimiter | } }模式三SAS Tokensink { AzureQueueStorage { queue_name events authentication_type sas_token endpoint https://myaccount.queue.core.windows.net sas_token sv...sig... message_encoding base64 } }三个示例同时演示了formatjson/text与message_encodingbase64的典型搭配。本地开发时也可用 Azurite 的连接字符串走connection_string模式避免依赖真实 Azure 账户。使用边界与排错要点结合文档与源码实际落地时建议关注以下几点队列需预先创建名称必须符合 3–63 位小写字母/数字/单连字符规则配置阶段即校验认证互斥切换认证模式时记得删除其他模式的残留配置项否则启动即报not valid for the selected authentication_type消息大小编码后超过 64 KiB 会在发送前失败base64编码下原始负载上限约 48 KiB背压与超时若下游 Azure 变慢write会在operation_timeout_ms内拿不到发送许可而超时失败此时可评估调大max_in_flight/operation_timeout_msat-least-once任务失败重试可能重复投递消费端需幂等处理。延伸阅读官方 sink 文档docs/en/connectors/sink/AzureQueueStorage.md含 变更记录sink 公共参数docs/en/connectors/common-options/sink-common-options.md连接器源码模块seatunnel-connectors-v2/connector-azure-queue-storage配置解析与单测分别在config包如 AzureQueueSinkConfigTest与 AzureQueueStorageSinkWriterTest 中可用于验证上述校验与背压行为。【免费下载链接】seatunnelSeaTunnel is a multimodal, high-performance, distributed, massive data integration tool.项目地址: https://gitcode.com/GitHub_Trending/se/seatunnel创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考