Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
Kafka and reactive spring boot program
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
Ramakrushna Sahoo
Kafka and reactive spring boot program
Commits
7b47da44
Commit
7b47da44
authored
7 months ago
by
Ramakrushna Sahoo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update file with some changes
parent
4c7a2e14
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
EmployeeController.java
src/main/java/com/main/controller/EmployeeController.java
+16
-14
EmployeeProducer.java
src/main/java/com/main/producer/EmployeeProducer.java
+2
-0
No files found.
src/main/java/com/main/controller/EmployeeController.java
View file @
7b47da44
...
...
@@ -7,6 +7,7 @@ import com.main.producer.EmployeeProducer;
import
com.main.service.EmployeeService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
...
...
@@ -27,7 +28,7 @@ public class EmployeeController {
@GetMapping
(
"/getEmpById/{id}"
)
public
Mono
<
Employee
>
getEmployeeById
(
@PathVariable
Integer
id
){
public
Mono
<
ResponseEntity
<
Employee
>
>
getEmployeeById
(
@PathVariable
Integer
id
){
Mono
<
Employee
>
mono
=
service
.
getById
(
id
)
.
doOnNext
(
emp
->
{
try
{
...
...
@@ -41,7 +42,8 @@ public class EmployeeController {
return
mono
;
return
mono
.
map
(
ResponseEntity:
:
ok
)
.
defaultIfEmpty
(
ResponseEntity
.
notFound
().
build
());
}
@GetMapping
(
"/getAll"
)
...
...
@@ -64,18 +66,18 @@ public class EmployeeController {
.
doOnNext
(
value
->
log
.
info
(
"Employee data fetched successfully: {}"
,
value
))
.
doOnError
(
error
->
log
.
error
(
"Data not found"
,
error
));
//
Collect employees into a list and send to producer
//
flux.collectList()
//
.doOnNext(list -> {
//
try {
//
producer.sendEmployee(list);
//
} catch (JsonProcessingException e) {
//
throw new RuntimeException(e);
//
}
//
log.info("Employee list sent to producer: {}", list);
//
})
// .doOnError(error -> log.error("Error while sending employee list: {
}", error))
//
.subscribe();
//
Collect employees into a list and send to producer
flux
.
collectList
()
.
doOnNext
(
list
->
{
try
{
producer
.
sendEmployee
(
list
);
}
catch
(
JsonProcessingException
e
)
{
throw
new
RuntimeException
(
e
);
}
log
.
info
(
"Employee list sent to producer: {}"
,
list
);
})
.
doOnError
(
error
->
log
.
error
(
"Error while sending employee list: {0
}"
,
error
))
.
subscribe
();
return
flux
;
// Return the Flux for further processing
}
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/main/producer/EmployeeProducer.java
View file @
7b47da44
...
...
@@ -67,6 +67,8 @@ public class EmployeeProducer {
}
});
}
public
CompletableFuture
<
SendResult
<
Integer
,
String
>>
sendEmployee
(
Employee
emp
)
throws
JsonProcessingException
{
...
...
This diff is collapsed.
Click to expand it.
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