1

This question asks how to get event header data into the Function and the accepted answer says that there is a way.

How about the other side - is it possible to output events with header data? In the docs I found only how to do it in C#.

lbilger
  • 304
  • 1
  • 8
  • Can you clarify what "header data" is in this context? It appears the linked question is referring to the `Properties` collection rather than the AMQP Message `Header` section. Are the application properties what you're interested in? – Jesse Squire Oct 01 '21 at 14:23
  • Yes exactly, I want to set values in the `Properties` collection. To be more precise, I want to create an exact copy of an incoming message including its headers/`Properties` and the key/`PartitionKey`. I'm not that familiar with Event Hubs nomenclature as I have so far only used Kafka to access them. – lbilger Oct 02 '21 at 17:05

1 Answers1

1

I don't know of a way to do this with the output bindings; to my knowledge, those only support native Java types or a POJO. (ref)

However, it is possible to use the Java SDK directly in the body of the Function which would give you direct control over forming the EventData instance to be published - including the Properties collection and other metadata.

With respect to copying data, if you're looking to ensure that you've got an exact replica (other than broker-owned metadata) - you'll want to publish to the exact partition that you've read from. (see sample below)

Ensuring the partition key could be done a couple of different ways, depending on the configuration of the Event Hub replica. For the simple approach, just publishing using the partition key should ensure that the event ends up in the same partition on the replica - assuming that the number of partitions match exactly. (see sample below)

If your replica has a different number of partitions, you'll need to publish to the partition directly and manipulate the underlying AMQP Message to inject the partition key into the Message Annotations section manually by adding an item with the key x-opt-partition-key and value of the partition key that you'd like it to reflect. To do this, you'll need to use the EventData.getRawAmqpMessage method.

For more information:

Jesse Squire
  • 6,107
  • 1
  • 27
  • 30
  • Thanks! However, this would mean creating a new producer for each function invocation, right? Seems inefficient to me, or does Azure Functions optimize it somehow? – lbilger Oct 06 '21 at 08:56
  • You'd definitely want to create it as a singleton and inject via DI or as a static member in the scope of the Function app. Here's where my Java-Functions integration knowledge breaks down - both of those are valid approaches using .NET but I'm not sure how that works with the other language hosts. – Jesse Squire Oct 06 '21 at 14:48