Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
FMS_Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bashar.hussein
FMS_Project
Commits
8992b1a6
Commit
8992b1a6
authored
May 10, 2023
by
ReemyHasan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kafka producer-consumer ek rethinkdb
parent
d6474c12
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
37 additions
and
19 deletions
+37
-19
compiler.xml
.idea/compiler.xml
+3
-0
encodings.xml
.idea/encodings.xml
+1
-0
misc.xml
.idea/misc.xml
+1
-0
modules.xml
.idea/modules.xml
+1
-0
TrapController.java
.../java/com/example/consumer/controller/TrapController.java
+8
-8
Trap.java
consumer/src/main/java/com/example/consumer/entity/Trap.java
+1
-1
TrapRepository.java
.../java/com/example/consumer/repository/TrapRepository.java
+12
-0
TrapService.java
.../main/java/com/example/consumer/services/TrapService.java
+10
-10
0d2cdb10-8d12-4307-bcba-7fb2b6e6d142
data/rethinkdb_data/0d2cdb10-8d12-4307-bcba-7fb2b6e6d142
+0
-0
metadata
data/rethinkdb_data/metadata
+0
-0
No files found.
.idea/compiler.xml
View file @
8992b1a6
...
...
@@ -7,6 +7,7 @@
<sourceOutputDir
name=
"target/generated-sources/annotations"
/>
<sourceTestOutputDir
name=
"target/generated-test-sources/test-annotations"
/>
<outputRelativeToContentRoot
value=
"true"
/>
<module
name=
"UserManagement"
/>
<module
name=
"producer"
/>
<module
name=
"consumer"
/>
</profile>
...
...
@@ -14,10 +15,12 @@
<bytecodeTargetLevel>
<module
name=
"consumer"
target=
"17"
/>
<module
name=
"producer"
target=
"17"
/>
<module
name=
"UserManagement"
target=
"17"
/>
</bytecodeTargetLevel>
</component>
<component
name=
"JavacSettings"
>
<option
name=
"ADDITIONAL_OPTIONS_OVERRIDE"
>
<module
name=
"UserManagement"
options=
"-parameters"
/>
<module
name=
"consumer"
options=
"-parameters"
/>
<module
name=
"producer"
options=
"-parameters"
/>
</option>
...
...
.idea/encodings.xml
View file @
8992b1a6
...
...
@@ -3,5 +3,6 @@
<component
name=
"Encoding"
>
<file
url=
"file://$PROJECT_DIR$/consumer/src/main/java"
charset=
"UTF-8"
/>
<file
url=
"file://$PROJECT_DIR$/producer/src/main/java"
charset=
"UTF-8"
/>
<file
url=
"file://$PROJECT_DIR$/userManagement/src/main/java"
charset=
"UTF-8"
/>
</component>
</project>
\ No newline at end of file
.idea/misc.xml
View file @
8992b1a6
...
...
@@ -5,6 +5,7 @@
<list>
<option
value=
"$PROJECT_DIR$/consumer/pom.xml"
/>
<option
value=
"$PROJECT_DIR$/producer/pom.xml"
/>
<option
value=
"$PROJECT_DIR$/userManagement/pom.xml"
/>
</list>
</option>
</component>
...
...
.idea/modules.xml
View file @
8992b1a6
...
...
@@ -3,6 +3,7 @@
<component
name=
"ProjectModuleManager"
>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/.idea/SNMP Collector.iml"
filepath=
"$PROJECT_DIR$/.idea/SNMP Collector.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/userManagement/UserManagement.iml"
filepath=
"$PROJECT_DIR$/userManagement/UserManagement.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/consumer/consumer.iml"
filepath=
"$PROJECT_DIR$/consumer/consumer.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/producer/producer.iml"
filepath=
"$PROJECT_DIR$/producer/producer.iml"
/>
</modules>
...
...
consumer/src/main/java/com/example/consumer/controller/
Elastic
Controller.java
→
consumer/src/main/java/com/example/consumer/controller/
Trap
Controller.java
View file @
8992b1a6
package
com
.
example
.
consumer
.
controller
;
import
com.example.consumer.
repositor
y.Trap
;
import
com.example.consumer.services.
Elastic
Service
;
import
com.example.consumer.
entit
y.Trap
;
import
com.example.consumer.services.
Trap
Service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.kafka.annotation.KafkaListener
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -9,23 +9,23 @@ import org.springframework.web.bind.annotation.*;
@RestController
@CrossOrigin
(
origins
=
{
"http://localhost:5173"
})
@RequestMapping
(
"/api/elastic"
)
public
class
Elastic
Controller
{
public
class
Trap
Controller
{
@Autowired
private
ElasticService
elastic
Service
;
private
TrapService
trap
Service
;
@GetMapping
(
"/findAllTraps"
)
Iterable
<
Trap
>
findAll
(){
return
elastic
Service
.
getTraps
();
return
trap
Service
.
getTraps
();
}
@PostMapping
(
"/insertTraps"
)
public
Trap
insert
Product
(
@RequestBody
Trap
trap
){
return
elastic
Service
.
insertTrap
(
trap
);
public
Trap
insert
Trap
(
@RequestBody
Trap
trap
){
return
trap
Service
.
insertTrap
(
trap
);
}
@KafkaListener
(
topics
=
"Test"
)
public
void
handleKafkaMessage
(
String
message
)
{
elastic
Service
.
saveKafkaMessageToElastic
(
message
);
trap
Service
.
saveKafkaMessageToElastic
(
message
);
}
}
...
...
consumer/src/main/java/com/example/consumer/
repositor
y/Trap.java
→
consumer/src/main/java/com/example/consumer/
entit
y/Trap.java
View file @
8992b1a6
package
com
.
example
.
consumer
.
repositor
y
;
package
com
.
example
.
consumer
.
entit
y
;
import
lombok.AllArgsConstructor
;
...
...
consumer/src/main/java/com/example/consumer/repository/
Elastic
Repository.java
→
consumer/src/main/java/com/example/consumer/repository/
Trap
Repository.java
View file @
8992b1a6
package
com
.
example
.
consumer
.
repository
;
import
com.example.consumer.entity.Trap
;
import
org.springframework.data.elasticsearch.repository.ElasticsearchRepository
;
import
org.springframework.stereotype.Repository
;
public
interface
ElasticRepository
extends
ElasticsearchRepository
<
Trap
,
Integer
>
{
@Repository
public
interface
TrapRepository
extends
ElasticsearchRepository
<
Trap
,
Integer
>
{
}
consumer/src/main/java/com/example/consumer/services/
Elastic
Service.java
→
consumer/src/main/java/com/example/consumer/services/
Trap
Service.java
View file @
8992b1a6
package
com
.
example
.
consumer
.
services
;
import
com.example.consumer.repository.
Elastic
Repository
;
import
com.example.consumer.
repositor
y.Trap
;
import
com.example.consumer.repository.
Trap
Repository
;
import
com.example.consumer.
entit
y.Trap
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -9,15 +9,15 @@ import org.springframework.stereotype.Service;
@Service
public
class
Elastic
Service
{
public
class
Trap
Service
{
@Autowired
private
ElasticRepository
elastic
Repository
;
private
TrapRepository
trap
Repository
;
private
final
Logger
log
=
LoggerFactory
.
getLogger
(
Elastic
Service
.
class
);
private
final
Logger
log
=
LoggerFactory
.
getLogger
(
Trap
Service
.
class
);
public
Iterable
<
Trap
>
getTraps
()
{
try
{
return
elastic
Repository
.
findAll
();
return
trap
Repository
.
findAll
();
}
catch
(
Exception
e
)
{
log
.
error
(
"Error getting data from Elastic"
,
e
);
return
null
;
...
...
@@ -26,7 +26,7 @@ public class ElasticService {
public
Trap
insertTrap
(
Trap
trap
)
{
try
{
elastic
Repository
.
save
(
trap
);
trap
Repository
.
save
(
trap
);
log
.
info
(
"Data saved successfully in Elastic"
);
return
trap
;
...
...
@@ -38,18 +38,18 @@ public class ElasticService {
}
public
Trap
updateTrap
(
Trap
trap
,
int
id
)
{
Trap
trap1
=
elastic
Repository
.
findById
(
id
).
get
();
Trap
trap1
=
trap
Repository
.
findById
(
id
).
get
();
trap1
.
setTrap
(
trap
.
getTrap
());
return
trap1
;
}
public
void
deleteTrap
(
int
id
)
{
elastic
Repository
.
deleteById
(
id
);
trap
Repository
.
deleteById
(
id
);
}
public
void
saveKafkaMessageToElastic
(
String
message
)
{
try
{
Trap
trap
=
new
Trap
(
message
);
elastic
Repository
.
save
(
trap
);
trap
Repository
.
save
(
trap
);
log
.
info
(
"Data saved successfully in Elastic"
);
...
...
data/rethinkdb_data/0d2cdb10-8d12-4307-bcba-7fb2b6e6d142
View file @
8992b1a6
No preview for this file type
data/rethinkdb_data/metadata
View file @
8992b1a6
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment