Skip to content

Commit ea44f8f

Browse files
committed
Final Implementation
1 parent 413c986 commit ea44f8f

File tree

33 files changed

+847
-166
lines changed

33 files changed

+847
-166
lines changed

.idea/compiler.xml

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JMSPublisher/pom.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.tharindu.me.auctionSystem</groupId>
8+
<artifactId>Online-Auction-System</artifactId>
9+
<version>1.0</version>
10+
</parent>
11+
12+
<artifactId>JMSPublisher</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>11</maven.compiler.source>
16+
<maven.compiler.target>11</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>fish.payara.extras</groupId>
23+
<artifactId>payara-embedded-all</artifactId>
24+
<version>6.2025.4</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>javax.jms</groupId>
28+
<artifactId>javax.jms-api</artifactId>
29+
<version>2.0.1</version>
30+
<scope>provided</scope>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<artifactId>maven-compiler-plugin</artifactId>
38+
<version>3.10.1</version>
39+
<configuration>
40+
<!-- compile source for Java 11, even if your server runs Java 17 -->
41+
<release>11</release>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
48+
49+
</project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.tharindu.me.auctionSystem;
2+
3+
import jakarta.jms.*;
4+
5+
import javax.naming.InitialContext;
6+
import javax.naming.NamingException;
7+
import java.util.Scanner;
8+
9+
public class JMSPublisher {
10+
public static void main(String[] args) {
11+
try {
12+
InitialContext ctx = new InitialContext();
13+
TopicConnectionFactory TopicconnectionFactory =
14+
(TopicConnectionFactory) ctx.lookup("jms/myTopicConnectionFactory");
15+
System.out.println(TopicconnectionFactory);
16+
// OUTPUT ->> com.sun.messaging.jms.ra.ConnectionFactoryAdapter@6ace919c
17+
18+
TopicConnection connection = TopicconnectionFactory.createTopicConnection();
19+
connection.start();
20+
21+
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
22+
System.out.println(session);
23+
//OUTPUT ->> com.sun.messaging.jms.ra.SessionAdapter@7a1ddbf1
24+
25+
Topic topic = (Topic) ctx.lookup("jms/myTopic");
26+
session.createPublisher(topic);
27+
28+
TopicPublisher topicPublisher = session.createPublisher(topic);
29+
30+
Scanner scanner = new Scanner(System.in);
31+
System.out.println("Enter the message to be sent or type 'exit' to quit:");
32+
33+
while (true) {
34+
String line = scanner.nextLine();
35+
if (line.equalsIgnoreCase("exit")) {
36+
break;
37+
}
38+
TextMessage message = session.createTextMessage();
39+
message.setText(line);
40+
41+
topicPublisher.publish(message);
42+
}
43+
44+
} catch (NamingException | JMSException e) {
45+
throw new RuntimeException(e);
46+
}
47+
}
48+
}

JMSSubscriber/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.tharindu.me.auctionSystem</groupId>
8+
<artifactId>Online-Auction-System</artifactId>
9+
<version>1.0</version>
10+
</parent>
11+
12+
<artifactId>JMSSubscriber</artifactId>
13+
14+
<properties>
15+
<maven.compiler.source>11</maven.compiler.source>
16+
<maven.compiler.target>11</maven.compiler.target>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>fish.payara.extras</groupId>
23+
<artifactId>payara-embedded-all</artifactId>
24+
<version>6.2025.4</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>javax.jms</groupId>
28+
<artifactId>javax.jms-api</artifactId>
29+
<version>2.0.1</version>
30+
<scope>provided</scope>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<artifactId>maven-compiler-plugin</artifactId>
38+
<version>3.10.1</version>
39+
<configuration>
40+
<!-- compile source for Java 11, even if your server runs Java 17 -->
41+
<release>11</release>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.tharindu.me.auctionSystem;
2+
3+
import jakarta.jms.*;
4+
5+
import javax.naming.InitialContext;
6+
import javax.naming.NamingException;
7+
8+
public class JMSSubscriber {
9+
public static void main(String[] args) {
10+
try {
11+
InitialContext ctx = new InitialContext();
12+
TopicConnectionFactory TopicconnectionFactory =
13+
(TopicConnectionFactory) ctx.lookup("jms/myTopicConnectionFactory");
14+
System.out.println(TopicconnectionFactory);
15+
// OUTPUT ->> com.sun.messaging.jms.ra.ConnectionFactoryAdapter@6ace919c
16+
17+
TopicConnection connection = TopicconnectionFactory.createTopicConnection();
18+
connection.start();
19+
20+
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
21+
System.out.println(session);
22+
//OUTPUT ->> com.sun.messaging.jms.ra.SessionAdapter@7a1ddbf1
23+
24+
Topic topic = (Topic) ctx.lookup("jms/myTopic");
25+
26+
TopicSubscriber subscriber = session.createSubscriber(topic);
27+
// Message message = subscriber.receive();
28+
// System.out.println(message.getBody(String.class));
29+
30+
subscriber.setMessageListener(new MessageListener() {
31+
@Override
32+
public void onMessage(Message message) {
33+
try {
34+
String msg = message.getBody(String.class);
35+
System.out.println(msg);
36+
} catch (JMSException e) {
37+
throw new RuntimeException(e);
38+
}
39+
}
40+
});
41+
42+
while (true) {}
43+
} catch (NamingException | JMSException e) {
44+
throw new RuntimeException(e);
45+
}
46+
}
47+
}

README.md

Lines changed: 165 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,166 @@
1-
# Online-Auction-System
1+
# 🎉 Online Auction System
22

3+
> **Final Assignment** – A robust, enterprise-grade Online Auction System built with Jakarta EE, packaged as an EAR, leveraging ActiveMQ for async messaging and tested using JMeter and VisualVM.
4+
5+
---
6+
7+
## 🏗️ Project Overview
8+
9+
This system enables users to list items for auction, place bids in real time, and receive notifications when auctions conclude. Key features:
10+
11+
* **Modular Architecture:** Core entities, EJB business logic, web APIs, and EAR packaging.
12+
* **Asynchronous Messaging:** Notify winners and sellers via JMS queue (ActiveMQ).
13+
* **Performance Testing:** Validate scalability with Apache JMeter and profile JVM with VisualVM.
14+
15+
---
16+
17+
## 📦 Architecture & Modules
18+
19+
The repository follows an **Enterprise Archive (EAR)** structure:
20+
21+
```
22+
Online-Auction-System/
23+
├── core/ # JAR: JPA entities (User, Item, Auction, Bid), DTOs, DAOs
24+
├── ejb/ # EJB JAR: Stateless beans (AuctionServiceBean, BidServiceBean), JMS producers
25+
├── web/ # WAR: JAX-RS REST endpoints under /api (UserResource, AuctionResource, BidResource)
26+
├── ear/ # EAR: Aggregates core, ejb, web; contains application.xml & JMS resource descriptors
27+
├── pom.xml # Parent POM defining modules & dependency management
28+
├── .gitignore
29+
└── README.md # This document
30+
```
31+
32+
### Core Module (`core`)
33+
34+
* **Entities:** `User`, `Item`, `Auction`, `Bid` with JPA annotations.
35+
* **DAOs:** Generic CRUD operations via `EntityManager`.
36+
* **DTOs:** Data transfer objects for REST payloads.
37+
38+
### EJB Module (`ejb`)
39+
40+
* **`AuctionServiceBean`** (`@Stateless`): Create auctions, close auctions.
41+
* **`BidServiceBean`** (`@Stateless`): Place bids with concurrency control.
42+
* **JMS Producer:** Sends messages to notify users when auctions close.
43+
44+
```java
45+
@Resource(lookup = "jms/AuctionConnectionFactory")
46+
private ConnectionFactory cf;
47+
@Resource(lookup = "jms/AuctionQueue")
48+
private Queue queue;
49+
50+
public void notifyAuctionEnd(Auction auction) {
51+
try (JMSContext context = cf.createContext()) {
52+
context.createProducer()
53+
.send(queue, auction.getId().toString());
54+
}
55+
}
56+
```
57+
58+
### Web Module (`web`)
59+
60+
* **JAX-RS Resources:**
61+
62+
* `UserResource` for registration and login.
63+
* `AuctionResource` to list/create auctions.
64+
* `BidResource` to place bids (`POST /api/auctions/{id}/bids`).
65+
* **Security:** Basic authentication (EJB interceptor or Jakarta Security).
66+
67+
### EAR Module (`ear`)
68+
69+
* **`application.xml`:** Defines modules and context roots.
70+
* **JMS Resources:** Included in `META-INF` for server configuration:
71+
72+
```xml
73+
<resource-ref>
74+
<res-ref-name>jms/AuctionQueue</res-ref-name>
75+
<res-type>javax.jms.Queue</res-type>
76+
</resource-ref>
77+
```
78+
79+
---
80+
81+
## 🚦 ActiveMQ Integration
82+
83+
**Apache ActiveMQ** is our JMS broker for reliable, asynchronous messaging.
84+
85+
1. **Setup Broker:**
86+
87+
```bash
88+
brew install activemq # MacOS, or download ZIP for Windows/Linux
89+
activemq start # Starts broker at tcp://localhost:61616
90+
```
91+
2. **Define Resources in `broker.xml`:**
92+
93+
```xml
94+
<queue physicalName="AuctionQueue" />
95+
```
96+
3. **Producer Example:** See `ejb/src/main/java/.../AuctionServiceBean.java` above.
97+
4. **Consumer Example:** A separate EJB MDB listening on `jms/AuctionQueue`:
98+
99+
```java
100+
@MessageDriven(activationConfig = {
101+
@ActivationConfigProperty(propertyName="destination", propertyValue="AuctionQueue"),
102+
@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue")
103+
})
104+
public class AuctionNotificationMDB implements MessageListener {
105+
public void onMessage(Message msg) {
106+
String auctionId = msg.getBody(String.class);
107+
// Lookup winning bid and email user...
108+
}
109+
}
110+
```
111+
112+
---
113+
114+
## 🧪 Testing & Profiling
115+
116+
### 📊 Apache JMeter
117+
118+
Load-test REST endpoints to simulate high traffic:
119+
120+
1. **Design Test Plan:** Thread Group → HTTP Requests → Listeners.
121+
2. **Sample Command (Non-GUI):**
122+
123+
```bash
124+
jmeter -n -t AuctionTest.jmx \
125+
-l AuctionResults.jtl -e -o AuctionReport
126+
```
127+
3. **Key Metrics:** Throughput, Response Time, Error Rate.
128+
4. **Importance:** Validates scalability, identifies bottlenecks.
129+
130+
### 🖥️ VisualVM
131+
132+
Profile JVM performance in real time:
133+
134+
1. **Launch VisualVM:** bundled with JDK or standalone.
135+
2. **Attach** to running App Server process.
136+
3. **Monitor:** CPU, Heap, Threads, and perform **Heap Dumps**.
137+
4. **Profiler:** Drill down into hot methods in EJBs and DAOs.
138+
5. **Importance:** Detect memory leaks, thread contention, and heavy CPU usage.
139+
140+
---
141+
142+
## 🚀 Deployment & Quick Start
143+
144+
1. **Build All Modules:**
145+
146+
```bash
147+
mvn clean install
148+
```
149+
2. **Deploy EAR:**
150+
151+
```bash
152+
asadmin deploy ear/OnlineAuctionSystem.ear
153+
```
154+
3. **Start ActiveMQ** (see above).
155+
4. **Access API:** `http://localhost:8080/auction-web/api`
156+
157+
---
158+
159+
## 📄 License & Contact
160+
161+
MIT © 2025 Tharindu714
162+
Questions? Email: [contact@example.com](mailto:contact@example.com)
163+
164+
---
165+
166+
> Ready to bid? 🏷️ Happy coding and good luck on your final assignment!

0 commit comments

Comments
 (0)