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-kafka
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-kafka
Commits
7b8275ba
Commit
7b8275ba
authored
Aug 01, 2023
by
Julian Pulido
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change gRPC consume for rest consume
parent
78f9f818
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
11 deletions
+66
-11
src/main/java/com/cardiff/pocmeasurekafka/in/stream/MeasureConsumer.java
...om/cardiff/pocmeasurekafka/in/stream/MeasureConsumer.java
+1
-1
src/main/java/com/cardiff/pocmeasurekafka/out/grpc/GrpcAdapter.java
...ava/com/cardiff/pocmeasurekafka/out/grpc/GrpcAdapter.java
+3
-2
src/main/java/com/cardiff/pocmeasurekafka/out/rest/RestAdapter.java
...ava/com/cardiff/pocmeasurekafka/out/rest/RestAdapter.java
+52
-0
src/main/java/com/cardiff/pocmeasurekafka/service/MeasureService.java
...a/com/cardiff/pocmeasurekafka/service/MeasureService.java
+6
-7
src/main/resources/application-local.properties
src/main/resources/application-local.properties
+4
-1
No files found.
src/main/java/com/cardiff/pocmeasurekafka/in/stream/MeasureConsumer.java
View file @
7b8275ba
...
@@ -19,7 +19,7 @@ public class MeasureConsumer implements Consumer<Measure> {
...
@@ -19,7 +19,7 @@ public class MeasureConsumer implements Consumer<Measure> {
@Override
@Override
public
void
accept
(
Measure
measure
)
{
public
void
accept
(
Measure
measure
)
{
measureService
.
saveMeasure
Redis
(
measure
);
measureService
.
saveMeasure
(
measure
);
log
.
info
(
"Catch event {}"
,
measure
);
log
.
info
(
"Catch event {}"
,
measure
);
}
}
}
}
src/main/java/com/cardiff/pocmeasurekafka/out/grpc/GrpcAdapter.java
View file @
7b8275ba
...
@@ -16,6 +16,7 @@ import com.paloit.pocmeasuregrpc.MeasureServiceGrpc;
...
@@ -16,6 +16,7 @@ import com.paloit.pocmeasuregrpc.MeasureServiceGrpc;
import
com.paloit.pocmeasuregrpc.MeasureServiceGrpc.MeasureServiceBlockingStub
;
import
com.paloit.pocmeasuregrpc.MeasureServiceGrpc.MeasureServiceBlockingStub
;
@Component
@Component
@Deprecated
(
since
=
"01/08/2023"
)
public
class
GrpcAdapter
{
public
class
GrpcAdapter
{
@Value
(
"${grpc.adapter.host:localhost}"
)
@Value
(
"${grpc.adapter.host:localhost}"
)
...
@@ -23,7 +24,7 @@ public class GrpcAdapter {
...
@@ -23,7 +24,7 @@ public class GrpcAdapter {
@Value
(
"${grpc.adapter.port:9099}"
)
@Value
(
"${grpc.adapter.port:9099}"
)
private
int
port
;
private
int
port
;
public
String
createMeasure
(
Measure
measure
)
{
/*
public String createMeasure(Measure measure) {
ManagedChannel channel = ManagedChannelBuilder.forAddress(host, port)
ManagedChannel channel = ManagedChannelBuilder.forAddress(host, port)
.usePlaintext()
.usePlaintext()
.build();
.build();
...
@@ -35,5 +36,5 @@ public class GrpcAdapter {
...
@@ -35,5 +36,5 @@ public class GrpcAdapter {
.build());
.build());
channel.isShutdown();
channel.isShutdown();
return measureResponse.getDeviceId();
return measureResponse.getDeviceId();
}
}
*/
}
}
src/main/java/com/cardiff/pocmeasurekafka/out/rest/RestAdapter.java
0 → 100644
View file @
7b8275ba
package
com.cardiff.pocmeasurekafka.out.rest
;
import
java.io.Serializable
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.ZoneOffset
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
com.cardiff.pocmeasurekafka.model.Measure
;
@Component
public
class
RestAdapter
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RestAdapter
.
class
);
@Value
(
"${m3.api.url:http://localhost:8080/measure}"
)
private
String
m3ApiUrl
;
public
String
createMeasure
(
Measure
measure
){
RestTemplate
restTemplate
=
new
RestTemplate
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
HttpEntity
<
MeasureRest
>
requestEntity
=
new
HttpEntity
<>(
this
.
mapper
(
measure
),
headers
);
String
absoluteUri
=
UriComponentsBuilder
.
fromHttpUrl
(
m3ApiUrl
)
.
toUriString
();
ResponseEntity
<
String
>
response
=
restTemplate
.
exchange
(
absoluteUri
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
);
return
response
.
getBody
();
}
private
MeasureRest
mapper
(
Measure
measure
){
return
new
MeasureRest
(
measure
.
deviceId
(),
measure
.
value
(),
measure
.
date
().
toInstant
(
ZoneOffset
.
UTC
));
}
public
record
MeasureRest
(
String
deviceId
,
String
value
,
Instant
date
)
implements
Serializable
{
}
}
src/main/java/com/cardiff/pocmeasurekafka/service/MeasureService.java
View file @
7b8275ba
...
@@ -5,8 +5,8 @@ import org.slf4j.LoggerFactory;
...
@@ -5,8 +5,8 @@ import org.slf4j.LoggerFactory;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.cardiff.pocmeasurekafka.model.Measure
;
import
com.cardiff.pocmeasurekafka.model.Measure
;
import
com.cardiff.pocmeasurekafka.out.grpc.GrpcAdapter
;
import
com.cardiff.pocmeasurekafka.out.redis.RedisAdapter
;
import
com.cardiff.pocmeasurekafka.out.redis.RedisAdapter
;
import
com.cardiff.pocmeasurekafka.out.rest.RestAdapter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
...
@@ -16,15 +16,14 @@ public class MeasureService {
...
@@ -16,15 +16,14 @@ public class MeasureService {
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
MeasureService
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
MeasureService
.
class
);
private
final
RedisAdapter
redisAdapter
;
private
final
RedisAdapter
redisAdapter
;
private
final
GrpcAdapter
grpc
Adapter
;
private
final
RestAdapter
rest
Adapter
;
public
String
saveMeasureRedis
(
Measure
measure
){
public
void
saveMeasure
(
Measure
measure
){
String
deviceIdRedis
=
redisAdapter
.
saveMeasureRedis
(
measure
).
deviceId
();
String
deviceIdRedis
=
redisAdapter
.
saveMeasureRedis
(
measure
).
deviceId
();
log
.
info
(
"catch deviceID
response
redis {}"
,
deviceIdRedis
);
log
.
info
(
"catch deviceID
save in
redis {}"
,
deviceIdRedis
);
String
deviceIdFromRedis
=
redisAdapter
.
getByDeviceId
(
measure
.
deviceId
()).
deviceId
();
String
deviceIdFromRedis
=
redisAdapter
.
getByDeviceId
(
measure
.
deviceId
()).
deviceId
();
log
.
info
(
"catch deviceID getByDeviceId from redis {}"
,
deviceIdFromRedis
);
log
.
info
(
"catch deviceID getByDeviceId from redis {}"
,
deviceIdFromRedis
);
String
deviceIdGrpc
=
grpcAdapter
.
createMeasure
(
measure
);
String
deviceIdFromRest
=
restAdapter
.
createMeasure
(
measure
);
log
.
info
(
"catch deviceID response Grpc {}"
,
deviceIdRedis
);
log
.
info
(
"catch deviceID from m3 rest service consume {}"
,
deviceIdFromRest
);
return
deviceIdGrpc
;
}
}
}
}
src/main/resources/application-local.properties
View file @
7b8275ba
...
@@ -51,3 +51,6 @@ spring.cache.redis.time-to-live=1m
...
@@ -51,3 +51,6 @@ spring.cache.redis.time-to-live=1m
#GrpcEnpoint
#GrpcEnpoint
grpc.adapter.host
=
localhost
grpc.adapter.host
=
localhost
grpc.adapter.port
=
9099
grpc.adapter.port
=
9099
#RestEndpoint
m3.api.url
=
http://localhost:9099/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