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
P
poc-measure-rest
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
Operations
Operations
Metrics
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
Luis Eduardo Oviedo Granados
poc-measure-rest
Commits
1f004ead
Commit
1f004ead
authored
Aug 28, 2023
by
José Antonio Herrera Castillo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implements rabbitMQ rather than Kafka
parent
c3b25504
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
103 additions
and
30 deletions
+103
-30
docker-compose.yml
docker-compose.yml
+8
-14
pom.xml
pom.xml
+3
-3
src/main/java/com/cardif/pocmeasurerest/infra/controller/MeasureController.java
...if/pocmeasurerest/infra/controller/MeasureController.java
+3
-0
src/main/java/com/cardif/pocmeasurerest/infra/publisher/MeasureRabbitMQPublisher.java
...measurerest/infra/publisher/MeasureRabbitMQPublisher.java
+25
-0
src/main/java/com/cardif/pocmeasurerest/infra/publisher/MeasureRabbitMQPublisherConfig.java
...erest/infra/publisher/MeasureRabbitMQPublisherConfig.java
+46
-0
src/main/java/com/cardif/pocmeasurerest/infra/repository/MeasureRepositoryImpl.java
...ocmeasurerest/infra/repository/MeasureRepositoryImpl.java
+10
-6
src/main/java/com/cardif/pocmeasurerest/infra/repository/entity/MeasureEntity.java
...pocmeasurerest/infra/repository/entity/MeasureEntity.java
+2
-0
src/main/resources/application-local.properties
src/main/resources/application-local.properties
+6
-2
src/main/resources/application.properties
src/main/resources/application.properties
+0
-5
No files found.
docker-compose.yml
View file @
1f004ead
...
@@ -31,21 +31,15 @@ services:
...
@@ -31,21 +31,15 @@ services:
networks
:
networks
:
-
'
mongo'
-
'
mongo'
kafka
:
rabbitmq
:
image
:
landoop/fast-data-dev:latest
image
:
rabbitmq:3.12.3-management
environment
:
ADV_HOST
:
'
127.0.0.1'
RUNTESTS
:
0
FORWARDLOGS
:
0
SAMPLEDATA
:
0
ports
:
ports
:
-
2181:2181
# Zookeeper port
-
5672:5672
-
3030:3030
# Landoop UI port
-
15672:15672
#management
-
8081-8083:8081-8083
# REST Proxy, Schema Registry, Kafka Connect ports
environment
:
-
9581-9585:9581-9585
# JMX Ports
RABBITMQ_DEFAULT_USER
:
"
user"
-
9092:9092
# Kafka Broker port
RABBITMQ_DEFAULT_PASS
:
"
p@ssword"
networks
:
-
'
kafka'
networks
:
networks
:
kafka
:
kafka
:
...
...
pom.xml
View file @
1f004ead
...
@@ -30,11 +30,11 @@
...
@@ -30,11 +30,11 @@
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.
cloud
</groupId>
<groupId>
org.springframework.
boot
</groupId>
<artifactId>
spring-
cloud-starter-stream-kafka
</artifactId>
<artifactId>
spring-
boot-starter-amqp
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
<artifactId>
spring-boot-configuration-processor
</artifactId>
...
...
src/main/java/com/cardif/pocmeasurerest/infra/controller/MeasureController.java
View file @
1f004ead
...
@@ -2,6 +2,7 @@ package com.cardif.pocmeasurerest.infra.controller;
...
@@ -2,6 +2,7 @@ package com.cardif.pocmeasurerest.infra.controller;
import
com.cardif.pocmeasurerest.domain.model.Measure
;
import
com.cardif.pocmeasurerest.domain.model.Measure
;
import
com.cardif.pocmeasurerest.domain.service.MeasureService
;
import
com.cardif.pocmeasurerest.domain.service.MeasureService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -10,6 +11,7 @@ import java.util.Optional;
...
@@ -10,6 +11,7 @@ import java.util.Optional;
@RestController
@RestController
@CrossOrigin
(
"*"
)
@CrossOrigin
(
"*"
)
@RequestMapping
(
value
=
"/measure"
)
@RequestMapping
(
value
=
"/measure"
)
@Slf4j
public
class
MeasureController
{
public
class
MeasureController
{
private
final
MeasureService
measureService
;
private
final
MeasureService
measureService
;
...
@@ -20,6 +22,7 @@ public class MeasureController {
...
@@ -20,6 +22,7 @@ public class MeasureController {
@PostMapping
@PostMapping
public
Measure
save
(
@RequestBody
Measure
measure
)
{
public
Measure
save
(
@RequestBody
Measure
measure
)
{
log
.
info
(
"Create Measure by Rest, request: {}"
,
measure
);
return
measureService
.
save
(
measure
);
return
measureService
.
save
(
measure
);
}
}
...
...
src/main/java/com/cardif/pocmeasurerest/infra/publisher/MeasureRabbitMQPublisher.java
0 → 100644
View file @
1f004ead
package
com.cardif.pocmeasurerest.infra.publisher
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.Queue
;
import
org.springframework.amqp.rabbit.annotation.EnableRabbit
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
@Component
@EnableRabbit
@Slf4j
@RequiredArgsConstructor
public
class
MeasureRabbitMQPublisher
{
private
final
RabbitTemplate
rabbitTemplate
;
private
final
Queue
queue
;
public
void
sendMessage
(
Object
message
)
{
log
.
info
(
"Sending message {} to RabbitMQ..."
,
message
);
rabbitTemplate
.
convertAndSend
(
queue
.
getName
(),
message
);
log
.
info
(
"Message sent successfully"
);
}
}
src/main/java/com/cardif/pocmeasurerest/infra/publisher/MeasureRabbitMQPublisherConfig.java
0 → 100644
View file @
1f004ead
package
com.cardif.pocmeasurerest.infra.publisher
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.amqp.core.Queue
;
import
org.springframework.amqp.rabbit.connection.ConnectionFactory
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.amqp.support.converter.Jackson2JsonMessageConverter
;
import
org.springframework.amqp.support.converter.MessageConverter
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
public
class
MeasureRabbitMQPublisherConfig
{
@Value
(
"${spring.rabbitmq.queue}"
)
private
String
queueName
;
@Bean
public
Queue
queue
()
{
return
new
Queue
(
queueName
,
false
);
}
@Bean
public
MessageConverter
messageConverter
(
ObjectMapper
objectMapper
)
{
return
new
Jackson2JsonMessageConverter
(
objectMapper
);
}
@Bean
public
ObjectMapper
objectMapper
()
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
objectMapper
.
registerModule
(
new
JavaTimeModule
());
return
objectMapper
;
}
@Bean
public
AmqpTemplate
template
(
ConnectionFactory
connectionFactory
,
MessageConverter
messageConverter
)
{
RabbitTemplate
template
=
new
RabbitTemplate
(
connectionFactory
);
template
.
setMessageConverter
(
messageConverter
);
return
template
;
}
}
\ No newline at end of file
src/main/java/com/cardif/pocmeasurerest/infra/repository/MeasureRepositoryImpl.java
View file @
1f004ead
...
@@ -2,22 +2,24 @@ package com.cardif.pocmeasurerest.infra.repository;
...
@@ -2,22 +2,24 @@ package com.cardif.pocmeasurerest.infra.repository;
import
com.cardif.pocmeasurerest.domain.model.Measure
;
import
com.cardif.pocmeasurerest.domain.model.Measure
;
import
com.cardif.pocmeasurerest.domain.repository.MeasureRepository
;
import
com.cardif.pocmeasurerest.domain.repository.MeasureRepository
;
import
com.cardif.pocmeasurerest.infra.publisher.MeasureRabbitMQPublisher
;
import
com.cardif.pocmeasurerest.infra.repository.entity.MeasureEntity
;
import
com.cardif.pocmeasurerest.infra.repository.entity.MeasureEntity
;
import
org.springframework.cloud.stream.function.StreamBridge
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.stereotype.Repository
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.Optional
;
import
java.util.Optional
;
@Repository
@Repository
@Slf4j
public
class
MeasureRepositoryImpl
implements
MeasureRepository
{
public
class
MeasureRepositoryImpl
implements
MeasureRepository
{
private
final
JpaMeasureRepository
jpaMeasureRepository
;
private
final
JpaMeasureRepository
jpaMeasureRepository
;
private
final
StreamBridge
streamBridge
;
private
final
MeasureRabbitMQPublisher
rabbitMQPublisher
;
public
MeasureRepositoryImpl
(
JpaMeasureRepository
jpaMeasureRepository
,
StreamBridge
streamBridge
)
{
public
MeasureRepositoryImpl
(
JpaMeasureRepository
jpaMeasureRepository
,
MeasureRabbitMQPublisher
rabbitMQPublisher
)
{
this
.
jpaMeasureRepository
=
jpaMeasureRepository
;
this
.
jpaMeasureRepository
=
jpaMeasureRepository
;
this
.
streamBridge
=
streamBridge
;
this
.
rabbitMQPublisher
=
rabbitMQPublisher
;
}
}
@Override
@Override
...
@@ -27,9 +29,11 @@ public class MeasureRepositoryImpl implements MeasureRepository {
...
@@ -27,9 +29,11 @@ public class MeasureRepositoryImpl implements MeasureRepository {
entity
.
setDeviceId
(
measure
.
deviceId
());
entity
.
setDeviceId
(
measure
.
deviceId
());
entity
.
setValue
(
measure
.
value
());
entity
.
setValue
(
measure
.
value
());
MeasureEntity
entitySaved
=
jpaMeasureRepository
.
save
(
entity
);
MeasureEntity
entitySaved
=
jpaMeasureRepository
.
save
(
entity
);
streamBridge
.
send
(
"measureProducer"
,
entitySaved
);
var
measureSaved
=
new
Measure
(
entitySaved
.
getDeviceId
(),
entitySaved
.
getValue
(),
return
new
Measure
(
entitySaved
.
getDeviceId
(),
entitySaved
.
getValue
(),
entitySaved
.
getDate
());
entitySaved
.
getDate
());
log
.
info
(
"Publish Message: {}"
,
measureSaved
);
rabbitMQPublisher
.
sendMessage
(
measureSaved
);
return
measureSaved
;
}
}
@Override
@Override
...
...
src/main/java/com/cardif/pocmeasurerest/infra/repository/entity/MeasureEntity.java
View file @
1f004ead
package
com.cardif.pocmeasurerest.infra.repository.entity
;
package
com.cardif.pocmeasurerest.infra.repository.entity
;
import
lombok.ToString
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
@Document
(
collection
=
"measure"
)
@Document
(
collection
=
"measure"
)
@ToString
public
class
MeasureEntity
{
public
class
MeasureEntity
{
@Id
@Id
...
...
src/main/resources/application-local.properties
View file @
1f004ead
...
@@ -8,5 +8,9 @@ spring.data.mongodb.username=root
...
@@ -8,5 +8,9 @@ spring.data.mongodb.username=root
spring.data.mongodb.password
=
myPasswordMongo21c
spring.data.mongodb.password
=
myPasswordMongo21c
spring.data.mongodb.authentication-database
=
admin
spring.data.mongodb.authentication-database
=
admin
#Kafka configurations stream
# RabbitMQ Configuration
spring.cloud.stream.kafka.binder.brokers
=
localhost:9092
spring.rabbitmq.host
=
localhost
\ No newline at end of file
spring.rabbitmq.queue
=
measureConsumer
spring.rabbitmq.port
=
5672
spring.rabbitmq.username
=
user
spring.rabbitmq.password
=
p@ssword
\ No newline at end of file
src/main/resources/application.properties
View file @
1f004ead
...
@@ -23,8 +23,3 @@ spring.jackson.visibility.field=any
...
@@ -23,8 +23,3 @@ spring.jackson.visibility.field=any
spring.jackson.visibility.getter
=
none
spring.jackson.visibility.getter
=
none
spring.jackson.visibility.setter
=
none
spring.jackson.visibility.setter
=
none
spring.jackson.visibility.is-getter
=
none
spring.jackson.visibility.is-getter
=
none
spring.cloud.function.definition
=
measureConsumer
#Producer
spring.cloud.stream.bindings.measureProducer.destination
=
measure
\ No newline at end of file
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