Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
warehouse-management
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
1
Merge Requests
1
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
Ascend
warehouse-management
Commits
e7ef42e4
Commit
e7ef42e4
authored
May 05, 2021
by
Philippe Fonzin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
produce and consume from kafka
parent
28f95b55
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
1 deletion
+99
-1
pom.xml
pom.xml
+4
-0
Consumer.java
src/main/java/com/ascendfinalproject/warehouse/Consumer.java
+21
-0
Producer.java
src/main/java/com/ascendfinalproject/warehouse/Producer.java
+31
-0
WarehouseApplication.java
...om/ascendfinalproject/warehouse/WarehouseApplication.java
+1
-0
KafkaController.java
...ndfinalproject/warehouse/controllers/KafkaController.java
+27
-0
application.properties
src/main/resources/application.properties
+15
-1
No files found.
pom.xml
View file @
e7ef42e4
...
...
@@ -29,6 +29,10 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-webflux
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.kafka
</groupId>
<artifactId>
kafka-streams
</artifactId>
...
...
src/main/java/com/ascendfinalproject/warehouse/Consumer.java
0 → 100644
View file @
e7ef42e4
package
com
.
ascendfinalproject
.
warehouse
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.kafka.annotation.KafkaListener
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
@Service
public
class
Consumer
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Producer
.
class
);
// this is placeholder
@KafkaListener
(
topics
=
"fulfilled"
,
groupId
=
"WAREHOUSE_MANAGEMENT"
)
public
void
consume
(
String
message
)
throws
IOException
{
logger
.
info
(
String
.
format
(
"#### -> Consumed message -> %s"
,
message
));
}
}
src/main/java/com/ascendfinalproject/warehouse/Producer.java
0 → 100644
View file @
e7ef42e4
package
com
.
ascendfinalproject
.
warehouse
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.stereotype.Service
;
@Service
public
class
Producer
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Producer
.
class
);
private
static
final
String
FULFILLED
=
"fulfilled"
;
private
static
final
String
CANCELLED
=
"cancelled"
;
@Autowired
// publish messages to the topic
private
KafkaTemplate
<
String
,
String
>
kafkaTemplate
;
public
void
orderFulfilled
(
String
message
)
{
logger
.
info
(
String
.
format
(
"#### -> this order is fulfilled -> %s"
,
message
));
this
.
kafkaTemplate
.
send
(
FULFILLED
,
message
);
}
public
void
orderCancelled
(
String
message
)
{
logger
.
info
(
String
.
format
(
"#### -> this order is cancelled -> %s"
,
message
));
this
.
kafkaTemplate
.
send
(
CANCELLED
,
message
);
}
}
src/main/java/com/ascendfinalproject/warehouse/WarehouseApplication.java
View file @
e7ef42e4
...
...
@@ -11,3 +11,4 @@ public class WarehouseApplication {
}
}
src/main/java/com/ascendfinalproject/warehouse/controllers/KafkaController.java
0 → 100644
View file @
e7ef42e4
package
com
.
ascendfinalproject
.
warehouse
.
controllers
;
import
com.ascendfinalproject.warehouse.Producer
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
@RestController
@RequestMapping
(
value
=
"/kafka"
)
public
class
KafkaController
{
private
final
Producer
producer
;
@Autowired
KafkaController
(
Producer
producer
)
{
this
.
producer
=
producer
;
}
@PostMapping
(
value
=
"/fulfilled"
)
public
void
sendMessageToKafkaTopic
(
@RequestParam
(
"message"
)
String
message
)
{
this
.
producer
.
orderFulfilled
(
message
);
}
}
src/main/resources/application.properties
View file @
e7ef42e4
spring.data.mongodb.uri
=
mongodb+srv://warehouse1:ascendWarehouseProject@warehouse-cluster.xopll.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
spring.data.mongodb.database
=
test
\ No newline at end of file
spring.data.mongodb.database
=
test
server
:
port: 9000
spring
:
kafka
:
consumer
:
bootstrap-servers
:
localhost:9092
group-id
:
WAREHOUSE_MANAGEMENT
auto-offset-reset
:
earliest
key-deserializer
:
org.apache.kafka.common.serialization.StringDeserializer
value-deserializer
:
org.apache.kafka.common.serialization.StringDeserializer
producer
:
bootstrap-servers
:
localhost:9092
key-serializer
:
org.apache.kafka.common.serialization.StringSerializer
value-serializer
:
org.apache.kafka.common.serialization.StringSerializer
\ 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