Commit e3a1dcda authored by mohammad.salama's avatar mohammad.salama

Kafka,Java and Redis are Done - Swarm IP Issues

parent 95254bbd
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="ClientsGenerator" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>ClientsGenerator</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.3</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package org.example;
import redis.clients.jedis.Jedis;
public class DataBaseHandler
{
/*
* 192.168.137.17
* */
private static final String REDIS_HOST = "192.168.137.17";
private static final int REDIS_PORT = 6379;
private static final String BALANCE_FIELD = "balance";
private static Jedis jedis = new Jedis(REDIS_HOST, REDIS_PORT);
public static boolean addUser(String name , String location , Double balance)
{
String jsonData;
// if (!jsonData.isEmpty()) return false;
MyRecord myRecord = new MyRecord(location , balance, 0);
jsonData = myRecord.toString();
jedis.set(name , jsonData);
return true;
}
public static boolean editAmount(String name , double amount)
{
String jsonData = jedis.get(name);
MyRecord myRecord = new MyRecord();
boolean result = myRecord.modifyBalance(jsonData , amount);
jsonData = myRecord.toString();
if (jsonData == null) return false;
jedis.set(name , jsonData);
return result;
}
}
package org.example;
import redis.clients.jedis.Jedis;
import javax.swing.text.html.HTMLDocument;
import java.util.Scanner;
public class Main
{
private static void addUser(String name , String country , double balance)
{
/*String name,country;
Double balance;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter User Name");
name = scanner.nextLine();
System.out.println("Enter Country for User : " + name);
country = scanner.nextLine();
System.out.println("Enter Balance (Positive Numbers) for User : " + name+ " from : "+country);
balance = scanner.nextDouble();*/
boolean res = DataBaseHandler.addUser(name , country , balance);
if (res) System.out.println("Done");
else System.out.println("Error, User Taken of Negative balance of Connection Problem");
}
public static void main(String[] args)
{
//Jedis jedis = new Jedis("redisdb" , 6379);
addUser("ali" , "jableh",85543.997);
addUser("abd" , "hama",8554300.997);
addUser("mohammed" , "tartous",987.69);
}
}
\ No newline at end of file
package org.example;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class MyRecord
{
/*SET JohnDoe "{\"id\": 1, \"name\": \"John Doe\", \"email\": \"johndoe@example.com\"}"*/
private String country;
private Double balance;
private Integer warnings;
public MyRecord(){}
/*
data base key = our user name
*/
public MyRecord(String country , double balance , int warnings)
{
this.balance = balance;
this.country = country;
this.warnings = warnings;
}
@Override
public String toString()
{
String ans = null;
ObjectMapper objectMapper = new ObjectMapper();
try
{
ans = objectMapper.writeValueAsString(this);
}
catch (JsonProcessingException e)
{
throw new RuntimeException(e);
}
finally {return ans;}
}
public boolean modifyBalance(String jsonData , double amount)
{
try
{
MyRecord myRecord = reverseJson(jsonData);
if (myRecord.balance >= amount)
{
myRecord.balance -= amount;
return true;
}
return false;
}
catch (JsonProcessingException e)
{
throw new RuntimeException(e);
}
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Double getBalance() {
return balance;
}
public void setBalance(Double balance) {
this.balance = balance;
}
public Integer getWarnings() {
return warnings;
}
public void setWarnings(Integer warnings) {
this.warnings = warnings;
}
private MyRecord reverseJson(String json) throws JsonProcessingException
{
ObjectMapper objectMapper = new ObjectMapper();
MyRecord myRecord = objectMapper.readValue(json , MyRecord.class);
return myRecord;
}
}
......@@ -10,7 +10,9 @@
</component>
<component name="ChangeListManager">
<list default="true" id="68795978-b1a2-4702-95fa-e8e7afae617a" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/../BankingAPI/src/main/java/com/example/Application.java" beforeDir="false" afterPath="$PROJECT_DIR$/../BankingAPI/src/main/java/com/example/Application.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../ClientsGenerator/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../ClientsGenerator/src/main/java/org/example/DataBaseHandler.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../ClientsGenerator/src/main/java/org/example/MyRecord.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......
version: "3.9"
services:
redisdb:
image: redis:latest
networks:
- kafkaNetwork
producer:
image: banking_producer_image
depends_on:
- redisdb
ports:
- 8080:8080
networks:
- kafkaNetwork
consumer-account-manager:
image: account_manager_consumer_image
networks:
- kafkaNetwork
consumer-user-notification:
image: notification_consumer_image
networks:
- kafkaNetwork
consumer-reporting:
image: reporting_consumer_image
networks:
- kafkaNetwork
networks:
kafkaNetwork:
\ No newline at end of file
FROM openjdk:17
WORKDIR /app
COPY . /app/Consumer-Account-Manager.jar
CMD ["java", "-jar", "Consumer-Acount-Manager.jar"]
FROM openjdk:17
WORKDIR /app
COPY . /app/
CMD ["java", "-jar", "Consumer-Reporting.jar"]
FROM openjdk:17
WORKDIR /app
COPY . /app/
CMD ["java", "-jar", "Consumer.jar"]
FROM openjdk:17
WORKDIR /app
COPY . /app/
CMD ["java", "-jar", "BankingAPI.jar"]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment