-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2023-07 spring-30-endpoints-flow-components
- Loading branch information
Showing
31 changed files
with
960 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/build/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ |
49 changes: 49 additions & 0 deletions
49
2023-07/spring-30-endpoints-flow-components/endpoints-flow-components-exercise/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>ru.otus</groupId> | ||
<artifactId>endpoints-flow-components-exercise</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>ru.otus</groupId> | ||
<artifactId>endpoints-flow-components</artifactId> | ||
<version>1.0</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-integration</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>${apache.commons.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
<version>${snakeyaml.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
...ents/endpoints-flow-components-exercise/src/main/java/ru/otus/spring/integration/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ru.otus.spring.integration; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import ru.otus.spring.integration.services.OrderService; | ||
|
||
|
||
@SpringBootApplication | ||
public class App { | ||
public static void main(String[] args) { | ||
ConfigurableApplicationContext ctx = SpringApplication.run(App.class, args); | ||
OrderService orderService = ctx.getBean(OrderService.class); | ||
orderService.startGenerateOrdersLoop(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...omponents-exercise/src/main/java/ru/otus/spring/integration/config/IntegrationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ru.otus.spring.integration.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.integration.dsl.IntegrationFlow; | ||
import org.springframework.integration.dsl.MessageChannelSpec; | ||
import org.springframework.integration.dsl.MessageChannels; | ||
|
||
@SuppressWarnings("unused") | ||
@Configuration | ||
public class IntegrationConfig { | ||
@Bean | ||
public MessageChannelSpec<?, ?> itemsChannel() { | ||
return MessageChannels.queue(10); | ||
} | ||
|
||
@Bean | ||
public MessageChannelSpec<?, ?> foodChannel() { | ||
return MessageChannels.publishSubscribe(); | ||
} | ||
|
||
// TODO: create default poller | ||
|
||
@Bean | ||
public IntegrationFlow cafeFlow() { | ||
return IntegrationFlow.from(itemsChannel()) | ||
// TODO: cook OrderItem in the kitchen | ||
// TODO*: add splitter and aggregator | ||
// TODO: forward it to the publish subscriber channel | ||
.get(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...points-flow-components-exercise/src/main/java/ru/otus/spring/integration/domain/Food.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package ru.otus.spring.integration.domain; | ||
|
||
|
||
public class Food { | ||
|
||
private final String name; | ||
|
||
public Food(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...s-flow-components-exercise/src/main/java/ru/otus/spring/integration/domain/OrderItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ru.otus.spring.integration.domain; | ||
|
||
public class OrderItem { | ||
|
||
private final String itemName; | ||
|
||
public OrderItem(String itemName) { | ||
this.itemName = itemName; | ||
} | ||
|
||
public String getItemName() { | ||
return itemName; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...ints-flow-components-exercise/src/main/java/ru/otus/spring/integration/services/Cafe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ru.otus.spring.integration.services; | ||
|
||
|
||
import ru.otus.spring.integration.domain.Food; | ||
import ru.otus.spring.integration.domain.OrderItem; | ||
|
||
// TODO: add messaging gateway annotation | ||
public interface Cafe { | ||
|
||
// TODO: add gateway annotation with required channels | ||
Food process(OrderItem orderItem); | ||
} |
12 changes: 12 additions & 0 deletions
12
...ow-components-exercise/src/main/java/ru/otus/spring/integration/services/CafeGateway.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ru.otus.spring.integration.services; | ||
|
||
|
||
import ru.otus.spring.integration.domain.Food; | ||
import ru.otus.spring.integration.domain.OrderItem; | ||
|
||
// TODO: add messaging gateway annotation | ||
public interface CafeGateway { | ||
|
||
// TODO: add gateway annotation with required channels | ||
Food process(OrderItem orderItem); | ||
} |
17 changes: 17 additions & 0 deletions
17
...ow-components-exercise/src/main/java/ru/otus/spring/integration/services/CafeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ru.otus.spring.integration.services; | ||
|
||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.springframework.integration.annotation.Gateway; | ||
import org.springframework.integration.annotation.MessagingGateway; | ||
|
||
import ru.otus.spring.integration.domain.OrderItem; | ||
|
||
@MessagingGateway | ||
public interface CafeService { | ||
|
||
@Gateway(requestChannel = "itemsChannel", replyChannel = "foodChannel") | ||
List<Map<String, Object>> process(List<OrderItem> orderItem); | ||
} |
9 changes: 9 additions & 0 deletions
9
...components-exercise/src/main/java/ru/otus/spring/integration/services/KitchenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ru.otus.spring.integration.services; | ||
|
||
import ru.otus.spring.integration.domain.Food; | ||
import ru.otus.spring.integration.domain.OrderItem; | ||
|
||
public interface KitchenService { | ||
|
||
Food cook(OrderItem orderItem); | ||
} |
29 changes: 29 additions & 0 deletions
29
...onents-exercise/src/main/java/ru/otus/spring/integration/services/KitchenServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ru.otus.spring.integration.services; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import ru.otus.spring.integration.domain.Food; | ||
import ru.otus.spring.integration.domain.OrderItem; | ||
|
||
@Service | ||
@Slf4j | ||
public class KitchenServiceImpl implements KitchenService { | ||
|
||
@Override | ||
public Food cook(OrderItem orderItem) { | ||
log.info("Cooking {}", orderItem.getItemName()); | ||
delay(); | ||
log.info("Cooking {} done", orderItem.getItemName()); | ||
|
||
return new Food(orderItem.getItemName()); | ||
} | ||
|
||
private static void delay() { | ||
try { | ||
Thread.sleep(3000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...w-components-exercise/src/main/java/ru/otus/spring/integration/services/OrderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ru.otus.spring.integration.services; | ||
|
||
public interface OrderService { | ||
void startGenerateOrdersLoop(); | ||
} |
44 changes: 44 additions & 0 deletions
44
...mponents-exercise/src/main/java/ru/otus/spring/integration/services/OrderServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ru.otus.spring.integration.services; | ||
|
||
import org.apache.commons.lang3.RandomUtils; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import ru.otus.spring.integration.domain.Food; | ||
import ru.otus.spring.integration.domain.OrderItem; | ||
|
||
@Service | ||
@Slf4j | ||
public class OrderServiceImpl implements OrderService { | ||
private static final String[] MENU = {"coffee", "tea", "smoothie", "whiskey", "beer", "cola", "water"}; | ||
|
||
private final CafeGateway cafe; | ||
|
||
public OrderServiceImpl(CafeGateway cafe) { | ||
this.cafe = cafe; | ||
} | ||
|
||
@Override | ||
public void startGenerateOrdersLoop() { | ||
for (int i = 0; i < 10; i++) { | ||
OrderItem orderItem = generateOrderItem(); | ||
int num = i + 1; | ||
log.info("{}, New orderItem: {}", num, orderItem.getItemName()); | ||
Food food = cafe.process(orderItem); | ||
log.info("{}, Ready food: {}", num, food.getName()); | ||
delay(); | ||
} | ||
} | ||
|
||
private static OrderItem generateOrderItem() { | ||
return new OrderItem(MENU[RandomUtils.nextInt(0, MENU.length)]); | ||
} | ||
|
||
private void delay() { | ||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...nts-flow-components/endpoints-flow-components-exercise/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
logging: | ||
level: | ||
root: info | ||
|
||
org.springframework.integration: debug |
78 changes: 78 additions & 0 deletions
78
2023-07/spring-30-endpoints-flow-components/endpoints-flow-components-solution/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>ru.otus</groupId> | ||
<artifactId>endpoints-flow-components-solution</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>ru.otus</groupId> | ||
<artifactId>endpoints-flow-components</artifactId> | ||
<version>1.0</version> | ||
</parent> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-integration</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.yaml</groupId> | ||
<artifactId>snakeyaml</artifactId> | ||
<version>${snakeyaml.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>${apache.commons.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
<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> | ||
<configuration> | ||
<mainClass>ru.otus.spring.integration.App</mainClass> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
<version>${checkstyle-plugin.version}</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.puppycrawl.tools</groupId> | ||
<artifactId>checkstyle</artifactId> | ||
<version>${checkstyle.version}</version> | ||
</dependency> | ||
</dependencies> | ||
<configuration> | ||
<configLocation>${checkstyle.config.url}</configLocation> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
20 changes: 20 additions & 0 deletions
20
...ents/endpoints-flow-components-solution/src/main/java/ru/otus/spring/integration/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ru.otus.spring.integration; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import ru.otus.spring.integration.services.OrderService; | ||
|
||
@Slf4j | ||
@SpringBootApplication | ||
public class App { | ||
|
||
public static void main(String[] args) { | ||
ConfigurableApplicationContext ctx = SpringApplication.run(App.class, args); | ||
|
||
OrderService orderService = ctx.getBean(OrderService.class); | ||
orderService.startGenerateOrdersLoop(); | ||
} | ||
} |
Oops, something went wrong.