I have tried many options.

My Message Routing Custom Endpoint is set up in the Azure Portal. I use a partition key template as follows:

{deviceid}-{my_telemetry_date}, so that I can achieve a partition key with the following example value:

{"PartitionKey" : "FFFFFFFA-2023-10-22"}

where the {"my_telemetry_date" : "2023-10-22"}

I have tried the following syntaxes:

{deviceid}-{Body.my_telemetry_date} but results in:

{"PartitonKey" : "FFFFFFFA-{Body.my_telemetry_date}"}

{deviceid}-{Body.<my_telemetry_date>} but results in:

{"PartitonKey" : "FFFFFFFA-{Body.<my_telemetry_date>}"}

{deviceid}-{<my_telemetry_date>} but results in:

{"PartitonKey" : "FFFFFFFA-{<my_telemetry_date>}"}

{deviceid}-<my_telemetry_date> but results in:

{"PartitonKey" : "FFFFFFFA-<my_telemetry_date>"}

I need to append the Date contained in the telemetry data field my_telemtry_date onto the {deviceid}-

The {deviceid} is properly substituted, but cannot find any info on proper syntax to substitute a telemetry field's value in the Partition key template.

1

There are 1 answers

2
Matthijs van der Veer On BEST ANSWER

Unfortunately, you can't include telemetry values in your partition key using the built-in features of IoT Hub. The partition key only allows certain values per the docs:

The template for generating a synthetic partition key value for use with this Cosmos DB SQL Container. The template must include at least one of the following placeholders: {iothub}, {deviceid}, {DD}, {MM}, and {YYYY}. Any one placeholder may be specified at most once, but order and non-placeholder components are arbitrary. If partition key name is provided, partition key template defaults to {deviceid}-{YYYY}-{MM}.

If you need telemtry values to be part of the partition key, you will first need to route the message somewhere else (e.g. Azure Function) and from there pluck out the value and pass it to CosmosDB.