Azure / Azure/azure-functions-java-library

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

Ouverte
#229 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
area:java-functions
Langage dominant
Java
Étoiles
45
Forks
49
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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:
```java
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:
```java
@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)
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Start by tracing the conversion path in DataOperations.apply, DataSource.computeByType, and the RpcCollectionLongDataSource and RpcCollectionStringDataSource classes named in the traces. Reproduce the Kafka trigger with Cardinality.MANY and the OffsetArray and TopicArray bindings. Done means these metadata arrays no longer cause ClassCastException and the existing bindings still resolve correctly.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java
Domaine
backend
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
48/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.