0

我编写了一个 IoT 中心触发器,它在接收到数据时触发,并使用输出绑定将其写入 Datalake 存储。

当前输出绑定:

@BlobOutput(
        name = "target", 
        path = "event/iot-hub-1//BlobTrigger{rand-guid}.json") 

但我想指定输出应动态写入的路径,如下所示:

@BlobOutput(
        name = "target", 
        path = "event/iot-hub-1/{deviceId}/BlobTrigger{rand-guid}.json")

这是我编写的代码,似乎没有实现它。

完整代码:

   @FunctionName("OutputBind_trigger")
    public void run(
        @BindingName("SystemProperties") Map<String, Object> systemProperties,
        @EventHubTrigger(name = "message", eventHubName = "iot-hub-1", connection = "ConnectionString", consumerGroup = "$Default", cardinality = Cardinality.ONE) String message,
        @BlobOutput(
        name = "target", 
        path = "event/iot-hub-1/{deviceId}/BlobTrigger{rand-guid}.json")
      OutputBinding<String> outputItem, final ExecutionContext context )
      {
        context.getLogger().info("Java Event Hub trigger function executed.");
        context.getLogger().info("Event hub message received: " + message);
        deviceId = (String) systemProperties.get("iothub-connection-device-id");
        data =message.getBytes();
        System.out.println("Device Id is : "+deviceId);
        outputItem.setValue(new String(message.getBytes(), StandardCharsets.UTF_8));
      }

谁能让我知道我哪里出错了或者我可以动态编写它的方式。

4

0 回答 0