Skip to content

Instantly share code, notes, and snippets.

@apc-kamezaki
Last active June 14, 2021 01:19
Show Gist options
  • Save apc-kamezaki/d0f8d80eeb2a057535e1d12e82fc8f38 to your computer and use it in GitHub Desktop.
Save apc-kamezaki/d0f8d80eeb2a057535e1d12e82fc8f38 to your computer and use it in GitHub Desktop.
pgdemo-bff
@Service
@Slf4j
@RequiredArgsConstructor
public class DemoService {
private final BackendConfig backendConfig;
private final @Qualifier("backendWebClient") WebClient demoClient;
public Mono<Object> greeting() {
log.info("get greeting");
return demoClient.get().uri(String.format("%s/%s", backendConfig.getDemoBasePath(), "greetings"))
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Object.class);
}
public Mono<Object> tasks() {
log.info("get tasks");
return demoClient.get().uri(String.format("%s/%s", backendConfig.getDemoBasePath(), "tasks"))
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(Object.class);
}
}
@RestController
@RequiredArgsConstructor
@RequestMapping("/greeting-tasks")
public class GreetingTaskController {
private final DemoService demoService;
@RequestMapping()
public Mono<GreetingTask> get() {
return Mono.zip(demoService.greeting(), demoService.tasks())
.map(tuple -> {
final var greeting = tuple.getT1();
final var tasks = tuple.getT2();
return GreetingTask.builder().greeting(greeting).tasks(tasks).build();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment