Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
reactor-api-sample
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
vikram singh
reactor-api-sample
Commits
335be7ee
Commit
335be7ee
authored
Apr 06, 2020
by
vikram singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
separated the client and server
parent
23ea0734
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
5 additions
and
73 deletions
+5
-73
README.md
README.md
+3
-1
WebClientConfig.java
src/main/java/com/nisum/webflux/config/WebClientConfig.java
+0
-20
FruitController.java
...in/java/com/nisum/webflux/controller/FruitController.java
+0
-9
IFruitService.java
src/main/java/com/nisum/webflux/service/IFruitService.java
+0
-2
FruitService.java
...ain/java/com/nisum/webflux/service/impl/FruitService.java
+2
-41
No files found.
README.md
View file @
335be7ee
...
...
@@ -51,8 +51,10 @@ Run the Mongo shell, with the Mongo daemon running in one terminal, type ~/mongo
::::::::::::::::::::::::::::::::
Kafka installation::::
brew install kafka
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties
$
kafka-server-start /usr/local/etc/kafka/server.properties
kafka-server-start /usr/local/etc/kafka/server.properties
If we get any issue in running kafka server:
...
...
src/main/java/com/nisum/webflux/config/WebClientConfig.java
deleted
100755 → 0
View file @
23ea0734
package
com
.
nisum
.
webflux
.
config
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Scope
;
import
org.springframework.web.reactive.function.client.WebClient
;
@Configuration
public
class
WebClientConfig
{
@Bean
@Qualifier
(
"webclient"
)
@Scope
(
"prototype"
)
public
WebClient
.
Builder
getWebClient
()
{
return
WebClient
.
builder
();
}
}
src/main/java/com/nisum/webflux/controller/FruitController.java
View file @
335be7ee
...
...
@@ -89,15 +89,6 @@ public class FruitController {
return
fruitService
.
getAll
();
}
@GetMapping
(
"/getAllByWebClient"
)
public
Flux
<
Fruit
>
getAllByWebClient
(){
return
fruitService
.
getFruitsByWebClient
();
}
@GetMapping
(
"/saveFruitByWebClient"
)
public
Mono
<
Fruit
>
saveFruitsByWebClient
()
{
return
fruitService
.
saveFruitsByWebClient
();
}
@PostMapping
(
"/save"
)
public
Mono
<
Fruit
>
savetoMongo
(
@RequestBody
...
...
src/main/java/com/nisum/webflux/service/IFruitService.java
View file @
335be7ee
...
...
@@ -8,8 +8,6 @@ public interface IFruitService {
Mono
<
Fruit
>
save
(
Fruit
fruit
);
Flux
<
Fruit
>
getAll
();
Flux
<
Fruit
>
getFruitsByWebClient
();
Mono
<
Fruit
>
saveFruitsByWebClient
();
Mono
<
Fruit
>
getFruitById
(
String
id
);
Mono
<
Fruit
>
getFruitByPriceAndName
(
String
price
,
String
name
);
...
...
src/main/java/com/nisum/webflux/service/impl/FruitService.java
View file @
335be7ee
...
...
@@ -21,12 +21,6 @@ import java.util.stream.Collectors;
@Service
@Slf4j
public
class
FruitService
implements
IFruitService
{
private
final
WebClient
webClient
;
@Autowired
public
FruitService
(
@Qualifier
(
"webclient"
)
final
WebClient
.
Builder
webClientBuilder
)
{
this
.
webClient
=
webClientBuilder
.
build
();
}
@Autowired
FruitRepository
fruitRepository
;
...
...
@@ -41,41 +35,8 @@ public class FruitService implements IFruitService {
return
fruitRepository
.
findAll
().
collect
(
Collectors
.
maxBy
(
Comparator
.
comparing
(
e
->
Integer
.
parseInt
(
e
.
getPrice
())))).
map
(
Optional:
:
get
);
}
@Override
public
Flux
<
Fruit
>
getFruitsByWebClient
()
{
return
this
.
webClient
.
get
().
uri
(
"http://localhost:8080/getAll"
).
retrieve
()
.
onStatus
(
HttpStatus:
:
is4xxClientError
,
clientResponse
->
clientResponse
.
bodyToMono
(
Map
.
class
).
flatMap
(
e
->{
log
.
error
(
" 4XX error is occurred "
);
return
Mono
.
error
(
new
Exception
());
}))
.
onStatus
(
HttpStatus:
:
is5xxServerError
,
serverResponse
->
serverResponse
.
bodyToMono
(
Map
.
class
).
flatMap
(
e
->{
log
.
error
(
"there is 5XX error "
);
return
Mono
.
error
(
new
Exception
());
}))
.
bodyToFlux
(
Fruit
.
class
);
}
@Override
public
Mono
<
Fruit
>
saveFruitsByWebClient
()
{
Fruit
fruit
=
new
Fruit
();
fruit
.
setId
(
"45"
);
fruit
.
setName
(
"PineApple"
);
fruit
.
setPrice
(
"70"
);
return
this
.
webClient
.
post
().
uri
(
"http://localhost:8080/save"
)
.
body
(
BodyInserters
.
fromObject
(
fruit
))
.
retrieve
()
.
onStatus
(
HttpStatus:
:
is4xxClientError
,
clientResponse
->
clientResponse
.
bodyToMono
(
Map
.
class
).
flatMap
(
e
->{
log
.
error
(
" 4XX error is occurred "
);
return
Mono
.
error
(
new
Exception
());
}))
.
onStatus
(
HttpStatus:
:
is5xxServerError
,
serverResponse
->
serverResponse
.
bodyToMono
(
Map
.
class
).
flatMap
(
e
->{
log
.
error
(
"there is 5XX error "
);
return
Mono
.
error
(
new
Exception
());
}))
.
bodyToMono
(
Fruit
.
class
);
}
@Override
public
Flux
<
Fruit
>
getAll
()
{
return
fruitRepository
.
findAll
();
...
...
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