admin管理员组文章数量:1278910
I am sending Avro-serialized messages from Kafka to Azure Event Hubs using SchemaRegistryApacheAvroSerializer
. The schema is stored in Azure Schema Registry, and the producer sends events successfully.
public EventHubProducerService(
@Value("${EVENTHUB_CONNECTION_STRING}") String connectionString,
@Value("${eventhub.name}") String eventHubName,
@Value("${schema-registry.endpoint}") String schemaRegistryEndpoint,
@Value("${schema-registry.group}") String schemaRegistryGroup) {
tokenCredential = new DefaultAzureCredentialBuilder().build();
this.producerClient = new EventHubClientBuilder()
.connectionString(connectionString, eventHubName)
.buildProducerClient();
SchemaRegistryAsyncClient schemaRegistryClient = new SchemaRegistryClientBuilder()
.credential(tokenCredential)
.fullyQualifiedNamespace(schemaRegistryEndpoint)
.buildAsyncClient();
this.schemaRegistryApacheAvroSerializer = new SchemaRegistryApacheAvroSerializerBuilder()
.schemaRegistryClient(schemaRegistryClient)
.schemaGroup(schemaRegistryGroup)
.autoRegisterSchemas(true)
.avroSpecificReader(true)
.buildSerializer();
}
public void sendMessage(AgreementLifecycleDomainSourceType message) {
EventData eventData = schemaRegistryApacheAvroSerializer.serialize(
message, TypeReference.createInstance(EventData.class)
);
SendOptions sendOptions = new SendOptions().setPartitionId("1");
producerClient.send(Collections.singletonList(eventData), sendOptions);
}
When I connect this Event Hub to Microsoft Fabric Eventstream and try to preview the data, I get this error:
Source 'EventHubInputAdapter' had occurrences of kind 'InputDeserializerError.InvalidData'.
Invalid Avro Format.
Any insights would be helpful!
I am sending Avro-serialized messages from Kafka to Azure Event Hubs using SchemaRegistryApacheAvroSerializer
. The schema is stored in Azure Schema Registry, and the producer sends events successfully.
public EventHubProducerService(
@Value("${EVENTHUB_CONNECTION_STRING}") String connectionString,
@Value("${eventhub.name}") String eventHubName,
@Value("${schema-registry.endpoint}") String schemaRegistryEndpoint,
@Value("${schema-registry.group}") String schemaRegistryGroup) {
tokenCredential = new DefaultAzureCredentialBuilder().build();
this.producerClient = new EventHubClientBuilder()
.connectionString(connectionString, eventHubName)
.buildProducerClient();
SchemaRegistryAsyncClient schemaRegistryClient = new SchemaRegistryClientBuilder()
.credential(tokenCredential)
.fullyQualifiedNamespace(schemaRegistryEndpoint)
.buildAsyncClient();
this.schemaRegistryApacheAvroSerializer = new SchemaRegistryApacheAvroSerializerBuilder()
.schemaRegistryClient(schemaRegistryClient)
.schemaGroup(schemaRegistryGroup)
.autoRegisterSchemas(true)
.avroSpecificReader(true)
.buildSerializer();
}
public void sendMessage(AgreementLifecycleDomainSourceType message) {
EventData eventData = schemaRegistryApacheAvroSerializer.serialize(
message, TypeReference.createInstance(EventData.class)
);
SendOptions sendOptions = new SendOptions().setPartitionId("1");
producerClient.send(Collections.singletonList(eventData), sendOptions);
}
When I connect this Event Hub to Microsoft Fabric Eventstream and try to preview the data, I get this error:
Source 'EventHubInputAdapter' had occurrences of kind 'InputDeserializerError.InvalidData'.
Invalid Avro Format.
Any insights would be helpful!
Share Improve this question asked Feb 24 at 17:24 hamamhamam 557 bronze badges 1- Use this sample code to Serialize ``` PlayingCard playingCard = new PlayingCard(); playingCard.setPlayingCardSuit(PlayingCardSuit.SPADES); playingCard.setIsFaceCard(false); playingCard.setCardValue(5); MessageContent message = serializer.serialize(playingCard, TypeReference.createInstance(MessageContent.class));``` – Sampath Commented Feb 28 at 4:23
1 Answer
Reset to default 0The Invalid Avro Format
error that occurs when trying to deserialize Avro messages in Microsoft Fabric Eventstream from Azure Event Hubs can be resolved by using the following code:
PlayingCard playingCard = new PlayingCard();
playingCard.setPlayingCardSuit(PlayingCardSuit.SPADES);
playingCard.setIsFaceCard(false);
playingCard.setCardValue(5);
MessageContent message = serializer.serialize(playingCard,
TypeReference.createInstance(MessageContent.class));
In this case, change .avroSpecificReader(true)
to .avroSpecificReader(false)
.
Below is a sample code snippet for the Azure Schema Registry Apache Avro Serializer client library for Java with Azure Event Hubs. Refer to this GitHub repository for sample code on serialization and deserialization:
private final EventHubProducerClient producerClient;
private final SchemaRegistryApacheAvroSerializer schemaRegistryApacheAvroSerializer;
private final TokenCredential tokenCredential;
public EventHubProducerService(
String connectionString,
String eventHubName,
String schemaRegistryEndpoint,
String schemaRegistryGroup) {
tokenCredential = new DefaultAzureCredentialBuilder().build();
this.producerClient = new EventHubClientBuilder()
.connectionString(connectionString, eventHubName)
.buildProducerClient();
SchemaRegistryAsyncClient schemaRegistryClient = new SchemaRegistryClientBuilder()
.credential(tokenCredential)
.fullyQualifiedNamespace(schemaRegistryEndpoint)
.buildAsyncClient();
this.schemaRegistryApacheAvroSerializer = new SchemaRegistryApacheAvroSerializerBuilder()
.schemaRegistryClient(schemaRegistryClient)
.schemaGroup(schemaRegistryGroup)
.autoRegisterSchemas(true)
.avroSpecificReader(false)
.buildSerializer();
}
public void sendMessage(GenericRecord message) {
try {
EventData eventData = schemaRegistryApacheAvroSerializer.serialize(
message, TypeReference.createInstance(EventData.class)
);
System.out.println("Serialized Message: " + new String(eventData.getBody()));
SendOptions sendOptions = new SendOptions().setPartitionId("1");
producerClient.send(Collections.singletonList(eventData), sendOptions);
System.out.println("Message successfully sent to Event Hub.");
} catch (Exception e) {
System.err.println("Error sending Avro message: " + e.getMessage());
e.printStackTrace();
}
}
本文标签: javaAzure Event Hubs Avro Data Fails to Deserialize in Fabric EventstreamStack Overflow
版权声明:本文标题:java - Azure Event Hubs Avro Data Fails to Deserialize in Fabric Eventstream - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741251118a2365807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论