-
Notifications
You must be signed in to change notification settings - Fork 1
add spring integration #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package ru.otus.spring.hw.kanban; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.integration.annotation.IntegrationComponentScan; | ||
| import org.springframework.integration.channel.DirectChannel; | ||
| import org.springframework.integration.config.EnableIntegration; | ||
| import org.springframework.integration.dsl.IntegrationFlow; | ||
| import org.springframework.integration.dsl.channel.MessageChannels; | ||
| import ru.otus.spring.hw.kanban.domain.Board; | ||
| import ru.otus.spring.hw.kanban.dto.BoardDTO; | ||
| import ru.otus.spring.hw.kanban.repository.BoardRepository; | ||
| import ru.otus.spring.hw.kanban.service.BoardService; | ||
|
|
||
| @Configuration | ||
| @IntegrationComponentScan | ||
| @EnableIntegration | ||
| public class BoardIntegrationConfig { | ||
|
|
||
| @Bean(name = "createBoard.input") | ||
| public DirectChannel createBoardInputChannel() { | ||
| return MessageChannels.direct("createBoard.input").datatype(BoardDTO.class).get(); | ||
| } | ||
|
|
||
| @Bean(name = "getBoards.input") | ||
| public DirectChannel getBoardsChannel() { | ||
| return MessageChannels.direct("getBoards.input").datatype(String.class).get(); | ||
| } | ||
|
|
||
| @Bean(name = "updateBoard.input") | ||
| public DirectChannel updateBoardsChannel() { | ||
| return MessageChannels.direct("updateBoard.input").datatype(BoardDTO.class).get(); | ||
| } | ||
|
|
||
| @Bean(name = "deleteBoard.input") | ||
| public DirectChannel deleteBoardChannel() { | ||
| return MessageChannels.direct("deleteBoard.input").datatype(Integer.class).get(); | ||
| } | ||
|
|
||
|
|
||
| @Bean | ||
| public IntegrationFlow createBoard(BoardService boardService, BoardRepository boardRepository) { | ||
| return f -> f | ||
| .<BoardDTO, Board>transform(source -> source.fillBoard(new Board())) | ||
| .<Board>handle((payload, headers) -> boardRepository.save(payload)) | ||
| .<Board, BoardDTO>transform(source -> BoardDTO.fromBoard(source)); | ||
| } | ||
|
|
||
|
|
||
| @Bean | ||
| public IntegrationFlow getBoards(BoardRepository boardRepository) { | ||
| return f -> f | ||
| .<String, Boolean>route(s -> s != null && s.length() > 0, | ||
| mapping -> | ||
| mapping | ||
| .subFlowMapping(true, | ||
| flow -> flow.<String>handle((payload, headers) -> boardRepository.findBoardsByName(payload))) | ||
| .subFlowMapping(false, | ||
| flow -> flow.handle((payload, headers) -> boardRepository.findAll())) | ||
| ) | ||
| .split() | ||
| .<Board, BoardDTO>transform(BoardDTO::fromBoard) | ||
| .aggregate(); | ||
| } | ||
|
|
||
| @Bean | ||
| public IntegrationFlow updateBoard(BoardRepository boardRepository) { | ||
| return f -> f | ||
| .<BoardDTO, Board>transform(source -> { | ||
| Board board = boardRepository.findById(source.id).orElseThrow(() -> new RuntimeException("Not found board")); | ||
| source.fillBoard(board); | ||
| return board; | ||
| } | ||
| ) | ||
| .<Board>handle((payload, headers) -> boardRepository.save(payload)) | ||
| .<Board, BoardDTO>transform(BoardDTO::fromBoard); | ||
| } | ||
|
|
||
| @Bean | ||
| public IntegrationFlow deleteBoard(BoardService boardService, BoardRepository boardRepository) { | ||
| return f -> f | ||
| .<Integer, Board>transform(source -> boardRepository.findById(source).orElseThrow(() -> new RuntimeException("Object not founded"))) | ||
| .<Board>handle((payload, headers) -> boardService.delete(payload)); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package ru.otus.spring.hw.kanban.integration; | ||
|
|
||
| import org.springframework.integration.annotation.Gateway; | ||
| import org.springframework.integration.annotation.MessagingGateway; | ||
| import org.springframework.messaging.Message; | ||
| import ru.otus.spring.hw.kanban.dto.BoardDTO; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @MessagingGateway(name = "boardGateway") | ||
| public interface BoardMessagingGateway { | ||
|
|
||
| @Gateway(requestChannel = "createBoard.input") | ||
| BoardDTO createBoard(Message<BoardDTO> message); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Здесь не совсем правильно :) В смысле так можно, но гораздо лучше будет не оборачивать все в |
||
|
|
||
| @Gateway(requestChannel = "getBoards.input") | ||
| List<BoardDTO> getBoards(Message<String> get_all); | ||
|
|
||
| @Gateway(requestChannel = "updateBoard.input") | ||
| BoardDTO updateBoard(Message<BoardDTO> withPayload); | ||
|
|
||
| @Gateway(requestChannel = "deleteBoard.input") | ||
| void deleteBoard(Message<Integer> withPayload); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Класс!