Azure Blob Trigger动态路径配置失败及解决方案咨询
Hey there, let's break down why you're hitting that An item with the same key has already been added. Key: mm error and how to fix it properly.
What's Causing the Error?
The issue comes down to duplicate placeholder keys in your Blob Trigger path. When you use {mm} (for minutes) and {ss} (for seconds), these clash with Azure Functions' internal binding logic—some of these shorthand format identifiers are either reserved or get misinterpreted as duplicate keys during the trigger's indexing phase.
The Correct Path Configuration
Azure Functions Blob Trigger supports custom-named placeholders for dynamic path segments, so we just need to use clear, non-conflicting names that map directly to the structure of your Event Hub Capture output. Your Capture path is {Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}, so we'll adjust the trigger's path to match with explicit placeholder names.
Updated Code Example
@FunctionName("AzureBlogTriggerFn5") public void blobHandler( @BlobTrigger( name = "content", path = "uts-blobcontainer-nb-dev/uts-eventhubns/uts-nb-eventhub/{partitionId}/{year}/{month}/{day}/{hour}/{minute}/{second}/{fileName}", dataType = "binary", connection = "AzureWebJobsStorage" ) byte[] content, @BindingName("partitionId") String partitionId, @BindingName("year") String year, @BindingName("month") String month, @BindingName("day") String day, @BindingName("hour") String hour, @BindingName("minute") String minute, @BindingName("second") String second, @BindingName("fileName") String fileName, final ExecutionContext context ) throws StorageException, IOException, URISyntaxException, InvalidKeyException, InterruptedException { context.getLogger().info("Java Blob trigger function processed a blob. " + "\n File Name: " + fileName + "\n Partition ID: " + partitionId + "\n Capture Time: " + year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "\n Size: " + content.length + " Bytes"); }
Key Changes Explained
- Replace conflicting placeholders: Swap out
{partition}→{partitionId},{yyyy}→{year},{MM}→{month},{dd}→{day},{HH}→{hour},{mm}→{minute},{ss}→{second}. These explicit names avoid clashes with any reserved or internal keys. - Inject dynamic values (optional): If you need to use the partition ID or timestamp values in your code, add
@BindingNameannotations for each placeholder—this lets you access those values directly as method parameters. - Match Capture path structure: Ensure each placeholder lines up exactly with the segments in your Event Hub Capture path (e.g.,
PartitionIdin Capture maps to{partitionId}in the trigger path) so the trigger correctly detects new blobs.
Quick Checks to Verify
- Double-check that your container name (
uts-blobcontainer-nb-dev), Event Hub namespace (uts-eventhubns), and Event Hub name (uts-nb-eventhub) match exactly what's configured in your Event Hub Capture settings. - The trigger will automatically handle two-digit time/date segments (like
05for May or09for 9 AM) as string values, no extra formatting needed.
内容的提问来源于stack exchange,提问作者Niranjan Reddy

