Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Changes for Outbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Murphy committed Jul 27, 2020
1 parent 3336dee commit 1f46d93
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ hs_err_pid*
.project
.settings/
target/
.DS_Store
.vscode/settings.json
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.debezium.examples.outbox</groupId>
<artifactId>outbox-shipment-service</artifactId>
<name>Debezium Outbox Demo - Shipment Service</name>
<artifactId>trade-orders-service</artifactId>
<name>Debezium Outbox Demo - Trade Orders Service</name>
<version>1.0.0-SNAPSHOT</version>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/
package io.debezium.examples.outbox.trade.messagelog;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.Date;
import java.util.UUID;

import javax.persistence.Entity;
Expand All @@ -16,13 +18,12 @@ public class ConsumedMessage {

@Id
private UUID eventId;

private Instant timeOfReceiving;

ConsumedMessage() {
}

public ConsumedMessage(UUID eventId, Instant timeOfReceiving) {
public ConsumedMessage(UUID eventId, Instant timeOfReceiving){
this.eventId = eventId;
this.timeOfReceiving = timeOfReceiving;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
package io.debezium.examples.outbox.trade.model;

import java.time.LocalDateTime;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand All @@ -20,48 +21,85 @@ public class TradeOrder {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", updatable = false, nullable = false)
private Long id;

private long customerId;

// should be unique, but not doing so for the sake of restarts during demos
private long orderId;

private LocalDateTime orderDate;
private String orderType;
private Date openDate;
private String symbol;
private int quantity;
private BigDecimal price;
private BigDecimal orderFee;
private int accountId;

TradeOrder() {
}

public TradeOrder(Long customerId, long orderId, LocalDateTime orderDate) {
this.customerId = customerId;
this.orderId = orderId;
this.orderDate = orderDate;
public TradeOrder(long id, String orderType, Date openDate, String symbol, int quantity, BigDecimal price, BigDecimal orderFee, int accountId) {
this.id = id;
this.orderType = orderType;
this.openDate = openDate;
this.symbol = symbol;
this.quantity = quantity;
this.price = price;
this.orderFee = orderFee;
this.accountId = accountId;
}

public Long getId() {
return id;
}

public Long getCustomerId() {
return customerId;
public String getOrderType() {
return this.orderType;
}

public void setOrderType(String orderType) {
this.orderType = orderType;
}

public Date getOpenDate() {
return openDate;
}

public void setOpenDate(Date openDate) {
this.openDate = openDate;
}

public String getSymbol() {
return this.symbol;
}

public void setSymbol(String symbol){
this.symbol = symbol;
}

public int getQuantity() {
return this.quantity;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public BigDecimal getPrice() {
return this.price;
}

public void setCustomerId(Long customerId) {
this.customerId = customerId;
public void setPrice(BigDecimal price){
this.price = price;
}

public long getOrderId() {
return orderId;
public BigDecimal getOrderFee(){
return this.orderFee;
}

public void setOrderId(long orderId) {
this.orderId = orderId;
public void setOrderFee(BigDecimal orderFee){
this.orderFee = orderFee;
}

public LocalDateTime getOrderDate() {
return orderDate;
public int getAccountId(){
return this.accountId;
}

public void setOrderDate(LocalDateTime orderDate) {
this.orderDate = orderDate;
public void setAccountId(int accountId){
this.accountId = accountId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
package io.debezium.examples.outbox.trade.service;

import java.time.LocalDateTime;
import java.math.BigDecimal;
import java.util.Date;

import javax.enterprise.context.ApplicationScoped;
import javax.persistence.EntityManager;
Expand All @@ -32,11 +33,16 @@ public class TradeOrderService {
public void orderCreated(JsonNode event) {
LOGGER.info("Processing 'OrderCreated' event: {}", event);

final long orderId = event.get("id").asLong();
final long customerId = event.get("accountId").asLong();
final LocalDateTime orderDate = LocalDateTime.parse(event.get("openDate").asText());
final long id = event.get("id").asLong();
final String orderType = event.get("orderType").asText();
final Date openDate = new Date(event.get("openDate").asLong());
final String symbol = event.get("symbol").asText();
final int quantity = event.get("quantity").asInt();
final BigDecimal price = new BigDecimal(event.get("price").asText());
final BigDecimal orderFee= new BigDecimal(event.get("orderFee").asText());
final int accountId = event.get("accountId").asInt();

entityManager.persist(new TradeOrder(customerId, orderId, orderDate));
entityManager.persist(new TradeOrder(id, orderType, openDate, symbol, quantity, price, orderFee, accountId));
}

@Transactional(value=TxType.MANDATORY)
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Quarkus configuration file
# key = value
quarkus.datasource.driver=org.postgresql.Driver
quarkus.datasource.url=jdbc:postgresql://trade-db:5432/tradedb?currentSchema=inventory
quarkus.datasource.username=postgresuser
quarkus.datasource.password=postgrespw
quarkus.datasource.url=jdbc:postgresql://postgres:5432/tradedb
quarkus.datasource.username=tradedb
quarkus.datasource.password=tradedb
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.dialect=org.hibernate.dialect.PostgreSQLDialect
quarkus.hibernate-orm.log.sql=true

mp.messaging.incoming.orders.connector=smallrye-kafka
mp.messaging.incoming.orders.topic=Order.events
mp.messaging.incoming.orders.bootstrap.servers=kafka:9092
mp.messaging.incoming.orders.group.id=shipment-service
mp.messaging.incoming.orders.topic=outbox5.inventory.outboxevent
mp.messaging.incoming.orders.bootstrap.servers=morgan-cluster-kafka-bootstrap:9092
mp.messaging.incoming.orders.group.id=trade-order-service
mp.messaging.incoming.orders.key.deserializer=org.apache.kafka.common.serialization.StringDeserializer
mp.messaging.incoming.orders.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer

0 comments on commit 1f46d93

Please sign in to comment.