64 lines
2.6 KiB
Plaintext
64 lines
2.6 KiB
Plaintext
Spring Cloud Stream Sink Sample
|
|
==================================
|
|
|
|
## What is this app?
|
|
|
|
This is a Spring Boot application that is a Spring Cloud Stream sample sink app that inserts data into a database through JDBC.
|
|
This application specifically uses MySQL (MariaDB flavor) to insert the data.
|
|
In reality, you probably want to use the out of the box variant of JDBC sink from https://github.com/spring-cloud-stream-app-starters/jdbc which is more advanced.
|
|
Refer to the documentation of Spring Cloud Stream app starters for the latest links for generated apps for specific binders.
|
|
|
|
## What is the default binder used in this app?
|
|
|
|
The default binder used in this app is Kafka.
|
|
If you need to change it to Rabbitmq, change the appropriate dependency in the maven pom.xml
|
|
|
|
## Requirements
|
|
|
|
To run this sample, you will need to have installed:
|
|
|
|
* Java 8 or Above
|
|
|
|
## Running the application with Kafka binder
|
|
|
|
The following instructions assume that you are running Kafka and MySql as Docker images.
|
|
|
|
* Go to the application root
|
|
* `docker-compose up -d`
|
|
|
|
* Open another terminal
|
|
* Ensure that you have the `mysql` CLI tool installed and then use this command:
|
|
`mysql -u root -p -h 127.0.0.1 -P 3306 sample_mysql_db`
|
|
|
|
`sample_mysql_db` is the name of the database created by the mysql that is running in the docker container.
|
|
|
|
* Go back to the other terminal (root of this sample app `sink`)
|
|
* `./mvnw clean package`
|
|
|
|
When you start the app, it will create a table in the database.
|
|
See the method annotated with`PostConstruct` in the application for more details.
|
|
|
|
* `java -jar target/jdbc-sink-0.0.1-SNAPSHOT.jar`
|
|
|
|
The application has a convenient test source that sends to the same destination on the broker where the sink consumes data from.
|
|
This test source will send some test records every second.
|
|
Alternatively, you can connect to the topic using a Kafka console producer and send data in the format - `{"id":1,"name":"Bob","tag":"1}`.
|
|
If you go with this kafka console producer approach, make sure you comment out the test source in the sample and rebuild.
|
|
|
|
* Now go to your MySQL CLI:
|
|
|
|
`select * from test;`
|
|
|
|
Repeat the query a few times and you will see additional records each time.
|
|
|
|
## Running the application using Rabbit binder
|
|
|
|
All the instructions above apply here also, but instead of running the default `docker-compose.yml`, use the command below to start a Rabbitmq cluser.
|
|
|
|
* `docker-compose -f docker-compose-rabbit.yml up -d`
|
|
|
|
* `./mvnw clean package -P rabbit-binder`
|
|
|
|
* `java -jar target/sample-jdbc-sink-0.0.1-SNAPSHOT.jar`
|
|
|
|
Once you are done testing: `docker-compose -f docker-compose-rabbit.yml down` |