Skip to content

Commit fb5f52d

Browse files
committed
Command Dispatch with Kafka Enabled.
1 parent 4c8eb0e commit fb5f52d

File tree

17 files changed

+2731
-227
lines changed

17 files changed

+2731
-227
lines changed

k8s/server-depl.yaml

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,55 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
name: server-depl
4+
name: client-depl
5+
namespace: default
56
spec:
67
replicas: 1
78
selector:
89
matchLabels:
9-
app: server
10+
app: client
1011
template:
1112
metadata:
12-
name: server-pod
13+
name: client-pod
1314
labels:
14-
app: server
15+
app: client
1516
spec:
1617
containers:
17-
- name: server
18-
image: laithharb/server:v1
18+
- name: client
19+
image: laithharb/web-app:v1
1920
---
2021
apiVersion: v1
2122
kind: Service
2223
metadata:
23-
name: server-srv
24+
name: client-srv
25+
namespace: default
2426
spec:
2527
type: NodePort
2628
selector:
27-
app: server
29+
app: client
2830
ports:
2931
- port: 3000
3032
targetPort: 3000
31-
nodePort: 30005
32-
protocol: TCP
33+
nodePort: 30007
34+
protocol: TCP
35+
---
36+
apiVersion: networking.k8s.io/v1
37+
kind: Ingress
38+
metadata:
39+
annotations:
40+
nginx.ingress.kubernetes.io/rewrite-target: /$1
41+
name: rewrite
42+
namespace: default
43+
spec:
44+
ingressClassName: nginx
45+
rules:
46+
- host: auth.avaand.com
47+
http:
48+
paths:
49+
- path: /
50+
pathType: Prefix
51+
backend:
52+
service:
53+
name: client-srv
54+
port:
55+
number: 3000

logs/app.log

Lines changed: 2504 additions & 201 deletions
Large diffs are not rendered by default.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"type": "record",
3+
"name": "AccountCreatedEventAvro",
4+
"namespace": "org.wsd.app.event",
5+
"fields": [
6+
{
7+
"name": "id",
8+
"type": "string"
9+
},
10+
{
11+
"name": "accountHolder",
12+
"type": "string"
13+
},
14+
{
15+
"name": "accountType",
16+
"type": "string"
17+
},
18+
{
19+
"name": "createdAt",
20+
"type": {
21+
"type": "int",
22+
"logicalType": "date"
23+
}
24+
},
25+
{
26+
"name": "balance",
27+
"type": "double",
28+
"default": 0
29+
},
30+
{
31+
"name": "version",
32+
"type": "int",
33+
"default": 0
34+
}
35+
]
36+
}
File renamed without changes.

src/main/java/org/wsd/app/config/CQRSConfig.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44

55
package org.wsd.app.config;
66

7-
import jakarta.annotation.PostConstruct;
87
import org.axonframework.commandhandling.CommandBus;
98
import org.springframework.beans.factory.annotation.Autowired;
109
import org.springframework.context.ApplicationContext;
11-
import org.springframework.context.annotation.Bean;
1210
import org.springframework.context.annotation.Configuration;
13-
import org.springframework.stereotype.Component;
1411

1512
@Configuration
1613
public class CQRSConfig {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2024. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3+
*/
4+
5+
package org.wsd.app.core.api;
6+
7+
8+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
9+
import io.swagger.v3.oas.annotations.tags.Tag;
10+
import lombok.RequiredArgsConstructor;
11+
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.http.HttpStatus;
13+
import org.springframework.http.ResponseEntity;
14+
import org.springframework.web.bind.annotation.PostMapping;
15+
import org.springframework.web.bind.annotation.RequestMapping;
16+
import org.springframework.web.bind.annotation.RestController;
17+
import org.wsd.app.config.SwaggerConfig;
18+
import org.wsd.app.core.infrastructure.CommandDispatcher;
19+
import org.wsd.app.cqrs.commands.CreateAccountCommand;
20+
21+
import java.time.LocalDate;
22+
import java.util.UUID;
23+
24+
@RestController
25+
@RequiredArgsConstructor
26+
@RequestMapping("/api/accounts")
27+
@Tag(name = "Account Command Controller")
28+
@SecurityRequirement(name = SwaggerConfig.BEARER_TOKEN)
29+
public class AccountCommandController {
30+
31+
@Autowired
32+
private CommandDispatcher commandDispatcher;
33+
34+
@PostMapping("/create")
35+
public ResponseEntity<String> createAccount(CreateAccountCommand command) {
36+
UUID uuid = UUID.randomUUID();
37+
CreateAccountCommand createAccountCommand = CreateAccountCommand.builder()
38+
.id(uuid.toString())
39+
.accountHolder(command.getAccountHolder())
40+
.accountType(command.getAccountType())
41+
.createdAt(LocalDate.now())
42+
.balance(command.getBalance())
43+
.build();
44+
commandDispatcher.send(createAccountCommand);
45+
return ResponseEntity.status(HttpStatus.CREATED).body(uuid.toString());
46+
}
47+
48+
}

src/main/java/org/wsd/app/core/events/BaseEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
@AllArgsConstructor
1616
@SuperBuilder
1717
public abstract class BaseEvent extends Message {
18-
private int version;
18+
private int version = -1;
1919
}

src/main/java/org/wsd/app/core/infrastructure/CommandDispatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.wsd.app.core.commands.CommandHandler;
99

1010
public interface CommandDispatcher<T extends BaseCommand> {
11-
<T extends BaseCommand> void registerHandler(Class<T> type, CommandHandler<T> command);
11+
<T extends BaseCommand> void registerHandler(Class<T> type, CommandHandler command);
1212

1313
<T extends BaseCommand> void send(T command);
1414
}

src/main/java/org/wsd/app/core/infrastructure/EventStore.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package org.wsd.app.core.infrastructure;
66

77
import org.wsd.app.core.events.BaseEvent;
8-
import org.wsd.app.core.events.EventModel;
98
import org.wsd.app.cqrs.infrastructure.AggregateNotFoundException;
109

1110
import java.util.List;

src/main/java/org/wsd/app/cqrs/aggregate/AccountAggregate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.wsd.app.cqrs.events.CashDepositedEvent;
1414
import org.wsd.app.cqrs.events.CashWithdrawnEvent;
1515

16-
import java.util.Date;
16+
import java.time.LocalDate;
1717

1818
@Data
1919
@NoArgsConstructor
@@ -26,7 +26,7 @@ public AccountAggregate(CreateAccountCommand createAccountCommand) {
2626
AccountCreatedEvent.builder()
2727
.id(createAccountCommand.getId())
2828
.accountHolder(createAccountCommand.getAccountHolder())
29-
.createdAt(new Date())
29+
.createdAt(LocalDate.now())
3030
.accountType(createAccountCommand.getAccountType())
3131
.balance(createAccountCommand.getBalance())
3232
.build()

0 commit comments

Comments
 (0)