Gitlab - Argos ALM by PALO IT
Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
http-reactive-ms
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julian Pulido
http-reactive-ms
Commits
581f7da5
Commit
581f7da5
authored
Sep 07, 2023
by
Julian Pulido
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change package
parent
e6681eec
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
229 additions
and
91 deletions
+229
-91
docker-compose.yml
docker-compose.yml
+9
-0
pom.xml
pom.xml
+75
-69
src/main/java/com/example/http/reactive/HttpReactiveApplication.java
...va/com/example/http/reactive/HttpReactiveApplication.java
+40
-0
src/main/java/com/example/http/reactive/config/HttpReactiveHandler.java
...com/example/http/reactive/config/HttpReactiveHandler.java
+10
-4
src/main/java/com/example/http/reactive/config/HttpReactiveRouter.java
.../com/example/http/reactive/config/HttpReactiveRouter.java
+1
-3
src/main/java/com/example/http/reactive/consumer/RuleConsumer.java
...java/com/example/http/reactive/consumer/RuleConsumer.java
+22
-0
src/main/java/com/example/http/reactive/controller/HttpReactiveController.java
...mple/http/reactive/controller/HttpReactiveController.java
+38
-0
src/main/java/com/example/http/reactive/dto/Message.java
src/main/java/com/example/http/reactive/dto/Message.java
+2
-5
src/main/java/com/example/http/reactive/dto/Rule.java
src/main/java/com/example/http/reactive/dto/Rule.java
+2
-4
src/main/java/com/example/http/reactive/stream/MessageProducerAdapter.java
.../example/http/reactive/stream/MessageProducerAdapter.java
+4
-4
src/main/resources/application.properties
src/main/resources/application.properties
+26
-2
No files found.
docker-compose.yml
View file @
581f7da5
...
@@ -14,3 +14,12 @@ services:
...
@@ -14,3 +14,12 @@ services:
-
8081-8083:8081-8083
# REST Proxy, Schema Registry, Kafka Connect ports
-
8081-8083:8081-8083
# REST Proxy, Schema Registry, Kafka Connect ports
-
9581-9585:9581-9585
# JMX Ports
-
9581-9585:9581-9585
# JMX Ports
-
9092:9092
# Kafka Broker port
-
9092:9092
# Kafka Broker port
rabbit
:
image
:
rabbitmq:3-management
ports
:
-
5672:5672
-
15672:15672
environment
:
RABBITMQ_DEFAULT_USER
:
user
RABBITMQ_DEFAULT_PASS
:
pa55word
pom.xml
View file @
581f7da5
<?xml version="1.0" encoding="UTF-8"?>
<?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"
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>
4.0.0
</modelVersion>
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
org.springframework.boot
</groupId>
<parent>
<artifactId>
spring-boot-starter-parent
</artifactId>
<groupId>
org.springframework.boot
</groupId>
<version>
3.1.3
</version>
<artifactId>
spring-boot-starter-parent
</artifactId>
<relativePath/>
<!-- lookup parent from repository -->
<version>
3.1.3
</version>
</parent>
<relativePath/>
<!-- lookup parent from repository -->
<groupId>
com.example
</groupId>
</parent>
<artifactId>
http-reactive-ms
</artifactId>
<groupId>
com.example
</groupId>
<version>
0.0.1-SNAPSHOT
</version>
<artifactId>
http-reactive-ms
</artifactId>
<packaging>
war
</packaging>
<version>
0.0.1-SNAPSHOT
</version>
<name>
HttpReactive
</name>
<name>
HttpReactive
</name>
<description>
Demo project for Spring Boot
</description>
<description>
Demo project for Spring Boot
</description>
<properties>
<properties>
<java.version>
17
</java.version>
<java.version>
17
</java.version>
<spring-cloud.version>
2022.0.3
</spring-cloud.version>
<spring-cloud.version>
2022.0.3
</spring-cloud.version>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-webflux
</artifactId>
<artifactId>
spring-boot-starter-webflux
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-stream-binder-kafka-reactive
</artifactId>
<artifactId>
spring-cloud-starter-stream-kafka
</artifactId>
</dependency>
</dependency>
<dependency>
<!--<dependency>
<groupId>
org.projectlombok
</groupId>
<groupId>org.springframework.cloud</groupId>
<artifactId>
lombok
</artifactId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
<optional>
true
</optional>
</dependency>-->
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
io.micrometer
</groupId>
<artifactId>
micrometer-tracing-bridge-brave
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-stream-test-binder
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<dependency>
<dependencyManagement>
<groupId>
org.springframework.boot
</groupId>
<dependencies>
<artifactId>
spring-boot-starter-tomcat
</artifactId>
<dependency>
<scope>
provided
</scope>
<groupId>
org.springframework.cloud
</groupId>
</dependency>
<artifactId>
spring-cloud-dependencies
</artifactId>
<dependency>
<version>
${spring-cloud.version}
</version>
<groupId>
org.springframework.boot
</groupId>
<type>
pom
</type>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
import
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
</dependencies>
<dependency>
</dependencyManagement>
<groupId>
io.projectreactor
</groupId>
<artifactId>
reactor-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<dependencyManagement>
<build>
<dependencies>
<plugins>
<dependency>
<plugin>
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-cloud-dependencies
</artifactId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<version>
${spring-cloud.version}
</version>
</plugin>
<type>
pom
</type>
</plugins>
<scope>
import
</scope>
</build>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
</project>
src/main/java/com/example/http/reactive/HttpReactiveApplication.java
View file @
581f7da5
package
com.example.http.reactive
;
package
com.example.http.reactive
;
import
java.util.function.Consumer
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
import
com.example.http.reactive.dto.Message
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Hooks
;
@Slf4j
@SpringBootApplication
@SpringBootApplication
@RequiredArgsConstructor
public
class
HttpReactiveApplication
{
public
class
HttpReactiveApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
HttpReactiveApplication
.
class
,
args
);
SpringApplication
.
run
(
HttpReactiveApplication
.
class
,
args
);
Hooks
.
enableAutomaticContextPropagation
();
}
/*@Bean
Consumer<Message<Rule>> ruleConsumer(){
return rule -> log.info("Consumer rule: {}", rule);
}
@Bean
Consumer<Message<com.example.http.reactive.dto.Message>> messageConsumer(){
return message -> log.info("Consumer message: {}", message);
}*/
/*@Bean
Consumer<Flux<Rule>> ruleConsumer() {
return ruleFlux -> ruleFlux.
doOnNext(rule -> log.info("Consumer rule: {}", rule))
.subscribe();
}*/
@Bean
Consumer
<
Flux
<
Message
>>
messageConsumer
()
{
return
messageFlux
->
messageFlux
.
doOnNext
(
message
->
log
.
info
(
"Consumer message: {}"
,
message
))
.
subscribe
();
}
}
}
}
src/main/java/com/example/http/reactive/config/HttpReactiveHandler.java
View file @
581f7da5
...
@@ -9,27 +9,33 @@ import com.example.http.reactive.dto.Rule;
...
@@ -9,27 +9,33 @@ import com.example.http.reactive.dto.Rule;
import
com.example.http.reactive.stream.MessageProducerAdapter
;
import
com.example.http.reactive.stream.MessageProducerAdapter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
@Slf4j
@Component
@Component
@RequiredArgsConstructor
@RequiredArgsConstructor
public
class
HttpReactiveHandler
{
public
class
HttpReactiveHandler
{
private
final
MessageProducerAdapter
messageProducerAdapter
;
private
final
MessageProducerAdapter
messageProducerAdapter
;
record
Response
(
Boolean
status
,
Object
payload
){}
public
Mono
<
ServerResponse
>
publishMessage
(
ServerRequest
request
)
{
public
Mono
<
ServerResponse
>
publishMessage
(
ServerRequest
request
)
{
return
request
.
bodyToMono
(
Message
.
class
)
return
request
.
bodyToMono
(
Message
.
class
)
.
flatMap
(
requestObject
->
{
.
flatMap
(
requestObject
->
{
messageProducerAdapter
.
publishMessage
(
requestObject
);
log
.
info
(
"Before publish {}"
,
requestObject
);
return
ServerResponse
.
ok
().
bodyValue
(
requestObject
);
boolean
result
=
messageProducerAdapter
.
publishMessage
(
requestObject
);
return
ServerResponse
.
ok
().
bodyValue
(
new
Response
(
result
,
requestObject
));
});
});
}
}
public
Mono
<
ServerResponse
>
publishRule
(
ServerRequest
request
)
{
public
Mono
<
ServerResponse
>
publishRule
(
ServerRequest
request
)
{
return
request
.
bodyToMono
(
Rule
.
class
)
return
request
.
bodyToMono
(
Rule
.
class
)
.
flatMap
(
requestObject
->
{
.
flatMap
(
requestObject
->
{
messageProducerAdapter
.
publishMessage
(
requestObject
);
log
.
info
(
"Before publish {}"
,
requestObject
);
return
ServerResponse
.
ok
().
bodyValue
(
requestObject
);
boolean
result
=
messageProducerAdapter
.
publishMessage
(
requestObject
);
return
ServerResponse
.
ok
().
bodyValue
(
new
Response
(
result
,
requestObject
));
});
});
}
}
...
...
src/main/java/com/example/http/reactive/config/HttpReactiveRouter.java
View file @
581f7da5
package
com.example.http.reactive.config
;
package
com.example.http.reactive.config
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
server
.
RequestPredicates
.
accept
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -10,9 +11,6 @@ import org.springframework.web.reactive.function.server.RouterFunction;
...
@@ -10,9 +11,6 @@ import org.springframework.web.reactive.function.server.RouterFunction;
import
org.springframework.web.reactive.function.server.RouterFunctions
;
import
org.springframework.web.reactive.function.server.RouterFunctions
;
import
org.springframework.web.reactive.function.server.ServerResponse
;
import
org.springframework.web.reactive.function.server.ServerResponse
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
server
.
RequestPredicates
.
POST
;
import
static
org
.
springframework
.
web
.
reactive
.
function
.
server
.
RequestPredicates
.
accept
;
@Configuration
(
proxyBeanMethods
=
false
)
@Configuration
(
proxyBeanMethods
=
false
)
public
class
HttpReactiveRouter
{
public
class
HttpReactiveRouter
{
...
...
src/main/java/com/example/http/reactive/consumer/RuleConsumer.java
0 → 100644
View file @
581f7da5
package
com.example.http.reactive.consumer
;
import
java.util.function.Consumer
;
import
org.springframework.stereotype.Component
;
import
com.example.http.reactive.dto.Rule
;
import
lombok.extern.slf4j.Slf4j
;
import
reactor.core.publisher.Flux
;
@Slf4j
@Component
public
class
RuleConsumer
implements
Consumer
<
Flux
<
Rule
>>
{
@Override
public
void
accept
(
Flux
<
Rule
>
ruleFlux
)
{
ruleFlux
.
doOnNext
(
rule
->
log
.
info
(
"Consumer rule: {}"
,
rule
))
.
subscribe
();
}
}
src/main/java/com/example/http/reactive/controller/HttpReactiveController.java
0 → 100644
View file @
581f7da5
package
com.example.http.reactive.controller
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.example.http.reactive.dto.Message
;
import
com.example.http.reactive.dto.Rule
;
import
com.example.http.reactive.stream.MessageProducerAdapter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@RestController
@RequestMapping
(
"/block"
)
@RequiredArgsConstructor
public
class
HttpReactiveController
{
private
final
MessageProducerAdapter
messageProducerAdapter
;
record
Response
(
Boolean
status
,
Object
payload
){}
@PostMapping
(
"/publishMessage"
)
public
Response
publishMessage
(
@RequestBody
Message
message
){
log
.
info
(
"Before publish message {}"
,
message
);
Boolean
result
=
messageProducerAdapter
.
publishMessage
(
message
);
return
new
Response
(
result
,
message
);
}
@PostMapping
(
"/publishRule"
)
public
Response
publishRule
(
@RequestBody
Rule
rule
){
log
.
info
(
"Before publish rule {}"
,
rule
);
Boolean
result
=
messageProducerAdapter
.
publishMessage
(
rule
);
return
new
Response
(
result
,
rule
);
}
}
src/main/java/com/example/http/reactive/dto/Message.java
View file @
581f7da5
package
com.example.http.reactive.dto
;
package
com.example.http.reactive.dto
;
import
lombok.Getter
;
import
lombok.Data
;
import
lombok.Setter
;
@Getter
@Data
@Setter
public
class
Message
{
public
class
Message
{
private
String
message
;
private
String
message
;
}
}
src/main/java/com/example/http/reactive/dto/Rule.java
View file @
581f7da5
package
com.example.http.reactive.dto
;
package
com.example.http.reactive.dto
;
import
lombok.Getter
;
import
lombok.Data
;
import
lombok.Setter
;
@Getter
@Data
@Setter
public
class
Rule
{
public
class
Rule
{
private
String
ruleId
;
private
String
ruleId
;
...
...
src/main/java/com/example/http/reactive/stream/MessageProducerAdapter.java
View file @
581f7da5
...
@@ -14,12 +14,12 @@ public class MessageProducerAdapter {
...
@@ -14,12 +14,12 @@ public class MessageProducerAdapter {
private
final
StreamBridge
streamBridge
;
private
final
StreamBridge
streamBridge
;
public
void
publishMessage
(
Message
M
essage
){
public
boolean
publishMessage
(
Message
m
essage
){
streamBridge
.
send
(
"messageProducer"
,
M
essage
);
return
streamBridge
.
send
(
"messageProducer"
,
m
essage
);
}
}
public
void
publishMessage
(
Rule
rule
){
public
boolean
publishMessage
(
Rule
rule
){
streamBridge
.
send
(
"ruleProducer"
,
rule
);
return
streamBridge
.
send
(
"ruleProducer"
,
rule
);
}
}
}
}
src/main/resources/application.properties
View file @
581f7da5
spring.application.name
=
http-reactive-ms
#logging
logging.pattern.level
=
%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
# Stream
# Stream
spring.cloud.stream.kafka.binder.brokers
=
localhost:9092
spring.cloud.stream.kafka.binder.brokers
=
localhost:9092
#spring.rabbitmq.host=localhost
#spring.rabbitmq.username=user
#spring.rabbitmq.password=pa55word
#Producer
#Producer
spring.cloud.stream.bindings.messageProducer.destination
=
testMessage
spring.cloud.stream.bindings.messageProducer.destination
=
test.message-3
spring.cloud.stream.bindings.ruleProducer.destination
=
testRule
spring.cloud.stream.bindings.ruleProducer.destination
=
test.rule-3
#Consumer
spring.cloud.function.definition
=
ruleConsumer;messageConsumer
#Consumer testRule
spring.cloud.stream.bindings.ruleConsumer-in-0.destination
=
test.rule-3
spring.cloud.stream.bindings.ruleConsumer-in-0.group
=
${spring.application.name}
#Consumer testMessage
spring.cloud.stream.bindings.messageConsumer-in-0.destination
=
test.message-3
spring.cloud.stream.bindings.messageConsumer-in-0.group
=
${spring.application.name}
management.endpoints.jmx.exposure.exclude
=
*
management.endpoints.web.exposure.include
=
health,info,metrics,prometheus
management.info.git.enabled
=
true
management.info.java.enabled
=
true
management.info.os.enabled
=
true
logging.level.org.apache.kafka
=
ERROR
spring.cloud.stream.kafka.binder.enableObservation
=
true
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