Skip to content

[KafkaTrigger] Errors while retrieving function metadata using BindingName in cardinality=Cardinality.MANY mode #229

Description

@aloiva

Kafka trigger function has these metadata: Offset (long), Topic (string), key, partition, timestamp and headers. I was able to retrieve all this data using a basic function:

public class KafkaTriggerJava {
  @FunctionName("KafkaTriggerJava")
  public void run(
      @KafkaTrigger(
              name = "kafkaTrigger",
              topic = "test-topic",
              brokerList = "localhost:9092",
              authenticationMode = BrokerAuthenticationMode.PLAIN,
              protocol = BrokerProtocol.PLAINTEXT,
              consumerGroup = "test-group")
          String kafkaEventData,
      @BindingName("Key") String key,
      @BindingName("Offset") int offset,
      @BindingName("Partition") int partition,
      final ExecutionContext context) {
    context.getLogger().info("Payload: " + kafkaEventData);
  }
}

Then I set cardinality=Cardinality.MANY and tried the following binding names:

           @BindingName("KeyArray") Object[] key,
           @BindingName("OffsetArray") Object[] offset,
           @BindingName("TopicArray") Object[] topic,
           @BindingName("PartitionArray") Object[] partition,
           @BindingName("TimestampArray") Object[] timestamp, 
           @BindingName("HeadersArray") String[] headers

While I was able to get some of the data, "OffsetArray" and "TopicArray" ran into data conversion errors.
Trace for "OffsetArray":

Exception: ClassCastException: class com.microsoft.azure.functions.shaded.com.google.protobuf.LongArrayList cannot be cast to class java.lang.String (com.microsoft.azure.functions.shaded.com.google.protobuf.LongArrayList is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
Stack: java.lang.ClassCastException: class com.microsoft.azure.functions.shaded.com.google.protobuf.LongArrayList cannot be cast to class java.lang.String (com.microsoft.azure.functions.shaded.com.google.protobuf.LongArrayList is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
[2025-10-29T05:03:58.349Z]      at com.microsoft.azure.functions.worker.binding.DataOperations.apply(DataOperations.java:99)
[2025-10-29T05:03:58.352Z]      at com.microsoft.azure.functions.worker.binding.DataSource.computeByType(DataSource.java:56)
[2025-10-29T05:03:58.354Z]      at com.microsoft.azure.functions.worker.binding.RpcCollectionLongDataSource.computeByType(RpcCollectionLongDataSource.java:10)
[2025-10-29T05:03:58.356Z]      at com.microsoft.azure.functions.worker.binding.DataSource.computeByName(DataSource.java:42)
[2025-10-29T05:03:58.359Z]      at com.microsoft.azure.functions.worker.binding.RpcCollectionLongDataSource.computeByName(RpcCollectionLongDataSource.java:10)
[2025-10-29T05:03:58.361Z]      at com.microsoft.azure.functions.worker.binding.BindingDataStore.getTriggerMetatDataByName(BindingDataStore.java:72)
[2025-10-29T05:03:58.363Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:47)
[2025-10-29T05:03:58.365Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolveArguments(ParameterResolver.java:22)
[2025-10-29T05:03:58.367Z]      at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:20)
[2025-10-29T05:03:58.370Z]      at com.microsoft.azure.functions.worker.chain.FunctionExecutionMiddleware.invoke(FunctionExecutionMiddleware.java:19)
[2025-10-29T05:03:58.372Z]      at com.microsoft.azure.functions.worker.chain.InvocationChain.doNext(InvocationChain.java:21)
[2025-10-29T05:03:58.374Z]      at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:198)
[2025-10-29T05:03:58.376Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:34)
[2025-10-29T05:03:58.378Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[2025-10-29T05:03:58.380Z]      at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:44)
[2025-10-29T05:03:58.383Z]      at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:94)
[2025-10-29T05:03:58.385Z]      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2025-10-29T05:03:58.387Z]      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2025-10-29T05:03:58.390Z]      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2025-10-29T05:03:58.392Z]      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2025-10-29T05:03:58.394Z]      at java.base/java.lang.Thread.run(Thread.java:834)

Trace for "TopicArray":

Exception: ClassCastException: class com.microsoft.azure.functions.shaded.com.google.protobuf.LazyStringArrayList cannot be cast to class java.lang.String (com.microsoft.azure.functions.shaded.com.google.protobuf.LazyStringArrayList is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
Stack: java.lang.ClassCastException: class com.microsoft.azure.functions.shaded.com.google.protobuf.LazyStringArrayList cannot be cast to class java.lang.String (com.microsoft.azure.functions.shaded.com.google.protobuf.LazyStringArrayList is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
[2025-10-29T04:43:25.493Z]      at com.microsoft.azure.functions.worker.binding.DataOperations.apply(DataOperations.java:99)
[2025-10-29T04:43:25.495Z]      at com.microsoft.azure.functions.worker.binding.DataSource.computeByType(DataSource.java:56)
[2025-10-29T04:43:25.498Z]      at com.microsoft.azure.functions.worker.binding.RpcCollectionStringDataSource.computeByType(RpcCollectionStringDataSource.java:10)
[2025-10-29T04:43:25.500Z]      at com.microsoft.azure.functions.worker.binding.DataSource.computeByName(DataSource.java:42)
[2025-10-29T04:43:25.503Z]      at com.microsoft.azure.functions.worker.binding.RpcCollectionStringDataSource.computeByName(RpcCollectionStringDataSource.java:10)
[2025-10-29T04:43:25.506Z]      at com.microsoft.azure.functions.worker.binding.BindingDataStore.getTriggerMetatDataByName(BindingDataStore.java:72)
[2025-10-29T04:43:25.509Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:47)
[2025-10-29T04:43:25.512Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolveArguments(ParameterResolver.java:22)
[2025-10-29T04:43:25.515Z]      at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:20)
[2025-10-29T04:43:25.518Z]      at com.microsoft.azure.functions.worker.chain.FunctionExecutionMiddleware.invoke(FunctionExecutionMiddleware.java:19)
[2025-10-29T04:43:25.521Z]      at com.microsoft.azure.functions.worker.chain.InvocationChain.doNext(InvocationChain.java:21)
[2025-10-29T04:43:25.525Z]      at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:198)
[2025-10-29T04:43:25.528Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:34)
[2025-10-29T04:43:25.532Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[2025-10-29T04:43:25.536Z]      at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:44)
[2025-10-29T04:43:25.539Z]      at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:94)
[2025-10-29T04:43:25.543Z]      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2025-10-29T04:43:25.547Z]      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2025-10-29T04:43:25.550Z]      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2025-10-29T04:43:25.553Z]      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2025-10-29T04:43:25.556Z]      at java.base/java.lang.Thread.run(Thread.java:834)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions