Files
Soby Chacko 24997117d4 Spring Boot and Cloud updates
Update samples to use Boot 2.4.4
Spring Cloud is updated to 2020.0.2

Remove empty integration tests
2021-03-24 22:47:17 -04:00
..
2019-03-21 15:17:00 -04:00
2018-03-09 10:47:22 -05:00
2018-03-09 10:47:22 -05:00
2018-03-09 10:47:22 -05:00
2019-03-21 15:21:19 -04:00
2019-03-21 15:21:19 -04:00
2021-03-24 22:47:17 -04:00
2019-10-29 12:32:02 -04:00

Spring Cloud Stream StreamListener Basic Sample
================================================

In this *Spring Cloud Stream* sample, the application shows how to use StreamListener support to enable message mapping and automatic type conversion.

## Requirements

To run this sample, you will need to have installed:

* Java 8 or Above

## Code Tour

This sample is a Spring Boot application that bundles multiple application together to showcase how to use StreamListener to enable message mapping and automatic type conversion.

* TypeConversionApplication - the Spring Boot Main Application
* POJO's - Simple data classes - `Foo` and `Bar`
* SampleSource - the app that generates JSON string of the form `"{\"value\":\"hi\"}"` and then send that to an outbound channnel.
* SampleTransformer - the app that has the method annotated with `@StreamListener` to map the process input channel to a type `Bar`.
                      The annotation @SendTo on the `StreamListener` method will make sure to send the output to the provided output channel.
* SampleSink - the app that receives the converted message from the transformer output as type `Foo`.

Please note that the applications (SampleSource, SampleTransformer and SampleSink) are bundled inside the single application for the demo purpose only.
In practice, these applications run on their own.
If at all they need to be bundled together, the best practice is to use `AggregateApplicationBuilder`.
Refer the sample `aggregate-application` for more info on aggregate application.

## Running the application

The following instructions assume that you are running Kafka as a Docker image.

* Go to the application root
* `docker-compose up -d`

* `./mvnw clean package`

* `java -jar target/streamlistener-basic-0.0.1-SNAPSHOT-kafka.jar`

The application will log messages from source, transformer and sink.
Source sends a message every second which will initiate the processor and then the sink.
If you want to change this frequency, modify the `fixedDelay` parameter in the Source for the `InboundChannelAdapter`.
By default, you will see output similar to the following every second.

```
******************
At the Source
******************
Sending value: {"value":"hi"}
******************
At the transformer
******************
Received value hi of type class demo.Bar
Transforming the value to HI and with the type class demo.Bar
******************
At the Sink
******************
Received transformed message HI of type class demo.Foo
```
* `docker-compose down`

## 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/streamlistener-basic-0.0.1-SNAPSHOT-rabbit.jar`

Once you are done testing: `docker-compose -f docker-compose-rabbit.yml down`