Skip to content

Commit

Permalink
Add avro generated classes
Browse files Browse the repository at this point in the history
  • Loading branch information
carlesarnal committed Jan 18, 2024
1 parent 0467c4c commit 55ba002
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 3 deletions.
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<apicurio.registry.version>2.5.8.Final</apicurio.registry.version>
<slf4j.version>2.0.6</slf4j.version>
<quarkus.version>3.2.9.Final</quarkus.version>
<avro.version>1.11.3</avro.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -140,6 +141,28 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.avro</groupId>
<artifactId>avro-maven-plugin</artifactId>
<version>${avro.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>schema</goal>
</goals>
<configuration>
<stringType>String</stringType>
<imports>
<import>${project.basedir}/src/main/resources/avro/source.avsc</import>
<import>${project.basedir}/src/main/resources/avro/customer.avsc</import>
</imports>
<sourceDirectory>${project.basedir}/src/main/resources/avro</sourceDirectory>
<outputDirectory>${project.basedir}/target/generated-sources</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.eclipse.microprofile.reactive.messaging.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server1.inventory.customers.Envelope;
import server1.inventory.customers.Value;

import java.util.concurrent.CompletionStage;

Expand All @@ -22,11 +24,16 @@ public class ConsumedCustomersResource {
@Incoming("customers-from-kafka")
@Transactional
@Blocking
public CompletionStage<Void> consume(Message<CustomerEntity> customerMessage) {
final CustomerEntity customer = customerMessage.getPayload();
public CompletionStage<Void> consume(Message<Envelope> customerMessage) {
final Value customer = customerMessage.getPayload().getAfter();
try {
log.info("Deleting customer with email: {}", customer.getEmail());
customer.delete();
CustomerEntity customerEntity = new CustomerEntity();
customerEntity.setId((long) customer.getId());
customerEntity.setEmail(customer.getEmail());
customerEntity.setFirstName(customer.getFirstName());
customerEntity.setLastName(customer.getLastName());
customerEntity.delete();
} catch (Exception e) {
log.error("Exception detected in the Probe application: {}", e.getCause(), e);
return customerMessage.nack(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public class CustomerEntity extends PanacheEntityBase {
@Column
public String email;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getFirstName() {
return firstName;
}
Expand Down
95 changes: 95 additions & 0 deletions src/main/resources/avro/customer.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"type": "record",
"name": "Envelope",
"namespace": "server1.inventory.customers",
"fields": [
{
"name": "before",
"type": [
"null",
{
"type": "record",
"name": "Value",
"fields": [
{
"name": "id",
"type": {
"type": "int",
"connect.default": 0
},
"default": 0
},
{
"name": "first_name",
"type": "string"
},
{
"name": "last_name",
"type": "string"
},
{
"name": "email",
"type": "string"
}
],
"connect.name": "server1.inventory.customers.Value"
}
],
"default": null
},
{
"name": "after",
"type": [
"null",
"Value"
],
"default": null
},
{
"name": "source",
"type": "io.debezium.connector.postgresql.Source"
},
{
"name": "op",
"type": "string"
},
{
"name": "ts_ms",
"type": [
"null",
"long"
],
"default": null
},
{
"name": "transaction",
"type": [
"null",
{
"type": "record",
"name": "block",
"namespace": "event",
"fields": [
{
"name": "id",
"type": "string"
},
{
"name": "total_order",
"type": "long"
},
{
"name": "data_collection_order",
"type": "long"
}
],
"connect.version": 1,
"connect.name": "event.block"
}
],
"default": null
}
],
"connect.version": 1,
"connect.name": "server1.inventory.customers.Envelope"
}
84 changes: 84 additions & 0 deletions src/main/resources/avro/source.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"type": "record",
"name": "Source",
"namespace": "io.debezium.connector.postgresql",
"fields": [
{
"name": "version",
"type": "string"
},
{
"name": "connector",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": "ts_ms",
"type": "long"
},
{
"name": "snapshot",
"type": [
{
"type": "string",
"connect.version": 1,
"connect.parameters": {
"allowed": "true,last,false,incremental"
},
"connect.default": "false",
"connect.name": "io.debezium.data.Enum"
},
"null"
],
"default": "false"
},
{
"name": "db",
"type": "string"
},
{
"name": "sequence",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "schema",
"type": "string"
},
{
"name": "table",
"type": "string"
},
{
"name": "txId",
"type": [
"null",
"long"
],
"default": null
},
{
"name": "lsn",
"type": [
"null",
"long"
],
"default": null
},
{
"name": "xmin",
"type": [
"null",
"long"
],
"default": null
}
],
"connect.name": "io.debezium.connector.postgresql.Source"
}

0 comments on commit 55ba002

Please sign in to comment.