Skip to content

Commit 05bffc6

Browse files
authored
Init checkin (#875)
toll reader app
1 parent 1f4c1e2 commit 05bffc6

File tree

9 files changed

+385
-0
lines changed

9 files changed

+385
-0
lines changed

tolldemo/toll-reader/.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/

tolldemo/toll-reader/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Toll Reader Simulator
2+
3+
## Description
4+
5+
This application simualates a toll reader. It takes 1 parameter; sleep time betwen record generation. Default is 1000 ms (1 sec).
6+
7+
**NOTE:** the program will not stup until you kill it!
8+
9+
This example will generate a record each 500 ms (after DB warmup)
10+
11+
```shell
12+
target/toll-reader.output/default/toll-reader 500
13+
```
14+
15+
## Native Compile
16+
17+
To compile the application execute the following command:
18+
19+
```shell
20+
mvn clean -Pnative native:compile -DskipTests
21+
```
22+
23+
This will build a native image optimized for the build platform (requires the previous step):
24+
25+
```shell
26+
native-image --bundle-apply=target/toll-reader.nib -march=native
27+
```
28+
29+
## Record format
30+
31+
The application created records in a TXEventQ with the following JSON format.
32+
33+
```json
34+
{
35+
"accountnumber": 55468,
36+
"license-plate": "FL-69540",
37+
"cartype": "SUV",
38+
"tagid": 87967,
39+
"timestamp": "2024-04-18"
40+
}
41+
```

tolldemo/toll-reader/aq.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
begin
2+
dbms_aqadm.create_transactional_event_queue (queue_name => 'TollGate', multiple_consumers => true);
3+
dbms_aqadm.set_queue_parameter('TollGate', 'KEY_BASED_ENQUEUE', 2);
4+
dbms_aqadm.set_queue_parameter('TollGate', 'SHARD_NUM', 5);
5+
dbms_aqadm.start_queue('TollGate');
6+
end;
7+
8+
9+
begin
10+
dbms_aqadm.create_transactional_event_queue (queue_name => 'TollGate', multiple_consumers => false);
11+
--dbms_aqadm.set_queue_parameter('TollGate', 'KEY_BASED_ENQUEUE', 2);
12+
--dbms_aqadm.set_queue_parameter('TollGate', 'SHARD_NUM', 5);
13+
dbms_aqadm.start_queue('TollGate') ;
14+
end;
15+
16+
select msg_id, utl_raw.cast_to_varchar2(dbms_lob.substr(user_data)), msg_state from aq$tollgate;
17+
18+
begin
19+
dbms_aqadm.stop_queue('TollGate');
20+
dbms_aqadm.drop_queue('TollGate');
21+
end;

tolldemo/toll-reader/pom.xml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.2.5</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.example</groupId>
12+
<artifactId>toll-reader</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>tollreader</name>
15+
<description>Demo project for Spring Boot</description>
16+
<properties>
17+
<java.version>21</java.version>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>jakarta.json</groupId>
27+
<artifactId>jakarta.json-api</artifactId>
28+
<version>2.1.3</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.eclipse.parsson</groupId>
32+
<artifactId>parsson</artifactId>
33+
<version>1.1.5</version>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-test</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.oracle.database.spring</groupId>
44+
<artifactId>oracle-spring-boot-starter-aqjms</artifactId>
45+
<version>23.4.0</version>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.projectlombok</groupId>
50+
<artifactId>lombok</artifactId>
51+
<optional>true</optional>
52+
</dependency>
53+
54+
<!-- <dependency>
55+
<groupId>com.oracle.database.messaging</groupId>
56+
<artifactId>okafka</artifactId>
57+
<version>23.2.0.0</version>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>org.springframework.kafka</groupId>
62+
<artifactId>spring-kafka</artifactId>
63+
</dependency> -->
64+
</dependencies>
65+
66+
<build>
67+
<plugins>
68+
<plugin>
69+
<groupId>org.springframework.boot</groupId>
70+
<artifactId>spring-boot-maven-plugin</artifactId>
71+
</plugin>
72+
<plugin>
73+
<groupId>org.graalvm.buildtools</groupId>
74+
<artifactId>native-maven-plugin</artifactId>
75+
<configuration>
76+
<buildArgs combine.children="append">
77+
<buildArg>--bundle-create</buildArg>
78+
</buildArgs>
79+
</configuration>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
84+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example.tollreader;
2+
3+
public enum CarType {
4+
SUV("SUV"),
5+
PICKUP("PICKUP"),
6+
HATCHBACK("HATCHBACK"),
7+
SEDAN("SEDAN"),
8+
OTHER("OTHER");
9+
10+
private final String carType;
11+
12+
private CarType(String carType) {
13+
this.carType = carType;
14+
}
15+
16+
public String getStatusCode() {
17+
return this.carType;
18+
}
19+
20+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.example.tollreader;
2+
3+
public enum State {
4+
AL("Alabama"),
5+
MT("Montana"),
6+
AK("Alaska"),
7+
NE("Nebraska"),
8+
AZ("Arizona"),
9+
NV("Nevada"),
10+
AR("Arkansas"),
11+
NH("NewHampshire"),
12+
CA("California"),
13+
NJ("NewJersey"),
14+
CO("Colorado"),
15+
NM("NewMexico"),
16+
CT("Connecticut"),
17+
NY("NewYork"),
18+
DE("Delaware"),
19+
NC("NorthCarolina"),
20+
FL("Florida"),
21+
ND("NorthDakota"),
22+
GA("Georgia"),
23+
OH("Ohio"),
24+
HI("Hawaii"),
25+
OK("Oklahoma"),
26+
ID("Idaho"),
27+
OR("Oregon"),
28+
IL("Illinois"),
29+
PA("Pennsylvania"),
30+
IN("Indiana"),
31+
RI("RhodeIsland"),
32+
IA("Iowa"),
33+
SC("SouthCarolina"),
34+
KS("Kansas"),
35+
SD("SouthDakota"),
36+
KY("Kentucky"),
37+
TN("Tennessee"),
38+
LA("Louisiana"),
39+
TX("Texas"),
40+
ME("Maine"),
41+
UT("Utah"),
42+
MD("Maryland"),
43+
VT("Vermont"),
44+
MA("Massachusetts"),
45+
VA("Virginia"),
46+
MI("Michigan"),
47+
WA("Washington"),
48+
MN("Minnesota"),
49+
WV("WestVirginia"),
50+
MS("Mississippi"),
51+
WI("Wisconsin"),
52+
MO("Missouri"),
53+
WY("Wyoming");
54+
55+
private final String state;
56+
57+
private State(String state) {
58+
this.state = state;
59+
}
60+
61+
public String getStatusCode() {
62+
return this.state;
63+
}
64+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.example.tollreader;
2+
3+
import jakarta.jms.JMSException;
4+
import jakarta.jms.Message;
5+
import jakarta.jms.Session;
6+
import jakarta.json.Json;
7+
import jakarta.json.JsonObject;
8+
import lombok.extern.slf4j.Slf4j;
9+
10+
import java.time.format.DateTimeFormatter;
11+
import java.time.LocalDateTime;
12+
import java.security.SecureRandom;
13+
14+
import org.springframework.beans.factory.annotation.Autowired;
15+
import org.springframework.boot.CommandLineRunner;
16+
import org.springframework.boot.SpringApplication;
17+
import org.springframework.boot.autoconfigure.SpringBootApplication;
18+
import org.springframework.jms.annotation.EnableJms;
19+
import org.springframework.jms.core.JmsTemplate;
20+
import org.springframework.jms.core.MessageCreator;
21+
22+
@EnableJms
23+
@SpringBootApplication
24+
@Slf4j
25+
public class TollreaderApplication implements CommandLineRunner {
26+
27+
private static final SecureRandom random = new SecureRandom();
28+
private static final Integer minNumber = 10000;
29+
private static final Integer maxNumber = 99999;
30+
31+
@Autowired
32+
private JmsTemplate jmsTemplate;
33+
34+
private static <T extends Enum<?>> T randomEnum(Class<T> clazz) {
35+
int x = random.nextInt(clazz.getEnumConstants().length);
36+
return clazz.getEnumConstants()[x];
37+
}
38+
39+
// Why supresswarnings?
40+
@SuppressWarnings("null")
41+
private void sendMessage(JsonObject tolldata) {
42+
jmsTemplate.send("TollGate", new MessageCreator() {
43+
@Override
44+
public Message createMessage(Session session) throws JMSException {
45+
return session.createTextMessage(tolldata.toString());
46+
}
47+
48+
});
49+
}
50+
51+
@Override
52+
public void run(String... args) throws Exception {
53+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
54+
LocalDateTime now = LocalDateTime.now();
55+
String dateTimeString = now.format(formatter);
56+
57+
int sleepTime = 1000;
58+
if (args.length > 0 && !args[0].isBlank()) {
59+
sleepTime = Integer.parseInt(args[0]);
60+
}
61+
62+
log.info("Sleeptime :" + Integer.toString(sleepTime));
63+
64+
while (true) {
65+
int licNumber = random.nextInt(maxNumber - minNumber) + minNumber;
66+
int tagId = random.nextInt(maxNumber - minNumber) + minNumber;
67+
int accountNumber = random.nextInt(maxNumber - minNumber) + minNumber;
68+
String state = randomEnum(State.class).toString();
69+
String carType = randomEnum(CarType.class).toString();
70+
71+
JsonObject data = Json.createObjectBuilder()
72+
.add("accountnumber", accountNumber) // This could be looked up in the DB from the tagId?
73+
.add("license-plate", state + "-" + Integer.toString(licNumber)) // This could be looked up in the DB from the tagId?
74+
.add("cartype", carType) // This could be looked up in the DB from the tagId?
75+
.add("tagid", tagId)
76+
.add("timestamp", dateTimeString)
77+
.build();
78+
79+
log.info("Toll Data :" + data.toString());
80+
sendMessage(data);
81+
Thread.sleep(sleepTime);
82+
}
83+
}
84+
85+
public static void main(String[] args) {
86+
SpringApplication.run(TollreaderApplication.class, args);
87+
}
88+
89+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
spring:
2+
application:
3+
name: tollreader
4+
threads:
5+
virtual:
6+
enabled: true
7+
8+
datasource:
9+
url: jdbc:oracle:thin:@//localhost:1521/orclpdb1
10+
username: tolldemo
11+
password: Welcome12345
12+
driver-class-name: oracle.jdbc.OracleDriver
13+
type: oracle.ucp.jdbc.PoolDataSource
14+
oracleucp:
15+
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
16+
connection-pool-name: TollReaderConnectionPool
17+
initial-pool-size: 15
18+
min-pool-size: 10
19+
max-pool-size: 30
20+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.tollreader;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class TollreaderApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
13+
}

0 commit comments

Comments
 (0)