Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IntegrationProducerApps
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
Raghunath Josula
IntegrationProducerApps
Commits
4e0833b8
Commit
4e0833b8
authored
Feb 21, 2020
by
rjosula
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kafka Initial producer App code.
parent
01ea8fb8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
150 additions
and
0 deletions
+150
-0
pom.xml
KafkaProducerApp/pom.xml
+58
-0
KafkaProducerAppApplication.java
.../java/com/kafka/producer/KafkaProducerAppApplication.java
+13
-0
KakfaConfiguration.java
...in/java/com/kafka/producer/config/KakfaConfiguration.java
+38
-0
UserResource.java
...c/main/java/com/kafka/producer/resource/UserResource.java
+39
-0
appConfig.properties
KafkaProducerApp/src/main/resources/appConfig.properties
+1
-0
application.properties
KafkaProducerApp/src/main/resources/application.properties
+1
-0
No files found.
KafkaProducerApp/pom.xml
0 → 100644
View file @
4e0833b8
<?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"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.2.4.RELEASE
</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>
com.kafka.producer
</groupId>
<artifactId>
KafkaProducerApp
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
KafkaProducerApp
</name>
<description>
Voter Producer App
</description>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.kafka
</groupId>
<artifactId>
spring-kafka
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.common.models
</groupId>
<artifactId>
CommonBeanPojo
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>
com.fasterxml.jackson.core
</groupId>
<artifactId>
jackson-databind
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
KafkaProducerApp/src/main/java/com/kafka/producer/KafkaProducerAppApplication.java
0 → 100644
View file @
4e0833b8
package
com
.
kafka
.
producer
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
KafkaProducerAppApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
KafkaProducerAppApplication
.
class
,
args
);
}
}
KafkaProducerApp/src/main/java/com/kafka/producer/config/KakfaConfiguration.java
0 → 100644
View file @
4e0833b8
package
com
.
kafka
.
producer
.
config
;
import
org.apache.kafka.clients.producer.ProducerConfig
;
import
org.apache.kafka.common.serialization.StringSerializer
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.kafka.core.DefaultKafkaProducerFactory
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.kafka.core.ProducerFactory
;
import
org.springframework.kafka.support.serializer.JsonSerializer
;
import
com.common.pojos.User
;
import
java.util.HashMap
;
import
java.util.Map
;
@Configuration
public
class
KakfaConfiguration
{
@Bean
public
ProducerFactory
<
String
,
User
>
producerFactory
()
{
Map
<
String
,
Object
>
config
=
new
HashMap
<>();
config
.
put
(
ProducerConfig
.
BOOTSTRAP_SERVERS_CONFIG
,
"127.0.0.1:9092"
);
config
.
put
(
ProducerConfig
.
KEY_SERIALIZER_CLASS_CONFIG
,
StringSerializer
.
class
);
config
.
put
(
ProducerConfig
.
VALUE_SERIALIZER_CLASS_CONFIG
,
JsonSerializer
.
class
);
return
new
DefaultKafkaProducerFactory
<>(
config
);
}
@Bean
public
KafkaTemplate
<
String
,
User
>
kafkaTemplate
()
{
return
new
KafkaTemplate
<>(
producerFactory
());
}
}
KafkaProducerApp/src/main/java/com/kafka/producer/resource/UserResource.java
0 → 100644
View file @
4e0833b8
package
com
.
kafka
.
producer
.
resource
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.common.pojos.User
;
/**
* Kafka Controller used to produce the User data to the consumer application.
* @author rjosula
*
*/
@RestController
@RequestMapping
(
"kafka"
)
@PropertySource
(
"appConfig.properties"
)
public
class
UserResource
{
@Autowired
private
KafkaTemplate
<
String
,
User
>
kafkaTemplate
;
@Value
(
"${kafka.producer.topic.name}"
)
private
String
TOPIC
;
@RequestMapping
(
value
=
"/publish"
,
method
=
RequestMethod
.
POST
)
public
User
post
(
@RequestBody
User
user
)
{
kafkaTemplate
.
send
(
TOPIC
,
user
);
return
user
;
}
}
KafkaProducerApp/src/main/resources/appConfig.properties
0 → 100644
View file @
4e0833b8
kafka.producer.topic.name
=
Kafka_User_topic
\ No newline at end of file
KafkaProducerApp/src/main/resources/application.properties
0 → 100644
View file @
4e0833b8
server.port
=
8080
\ 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