Skip to content

Commit

Permalink
perf($ReactiveStarter): abstract beans
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
Johnny Miller (锺俊) committed Dec 29, 2020
1 parent 3ab8943 commit 8d1f040
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jmsoftware.maf.apigateway;

import com.jmsoftware.maf.apigateway.universal.configuration.ServerConfiguration;
import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty;
import com.jmsoftware.maf.reactivespringbootstarter.helper.IpHelper;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.SpringApplication;
Expand Down Expand Up @@ -29,11 +29,11 @@
public class ApiGatewayApplication {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static MafProjectProperty mafProjectProperty;
private static ServerConfiguration serverConfiguration;
private static IpHelper ipHelper;

public ApiGatewayApplication(MafProjectProperty mafProjectProperty, ServerConfiguration serverConfiguration) {
public ApiGatewayApplication(MafProjectProperty mafProjectProperty, IpHelper ipHelper) {
ApiGatewayApplication.mafProjectProperty = mafProjectProperty;
ApiGatewayApplication.serverConfiguration = serverConfiguration;
ApiGatewayApplication.ipHelper = ipHelper;
}

public static void main(String[] args) {
Expand All @@ -47,7 +47,7 @@ public static void main(String[] args) {
log.info("⏳ Deployment duration: {} seconds ({} ms)", duration.getSeconds(), duration.toMillis());
log.info("⏰ App started at {} (timezone - {})", endInstant, TimeZone.getDefault().getDisplayName());
log.info("{} App running at{} - Local: http://localhost:{}{}/{} - Network: {}/{}",
LINE_SEPARATOR, LINE_SEPARATOR, serverConfiguration.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, serverConfiguration.getBaseUrl(), mafProjectProperty.getContextPath());
LINE_SEPARATOR, LINE_SEPARATOR, ipHelper.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, ipHelper.getBaseUrl(), mafProjectProperty.getContextPath());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.jmsoftware.maf.reactivespringbootstarter.configuration;

import com.jmsoftware.maf.reactivespringbootstarter.controller.CommonController;
import com.jmsoftware.maf.reactivespringbootstarter.filter.AccessLogFilter;
import com.jmsoftware.maf.reactivespringbootstarter.helper.IpHelper;
import com.jmsoftware.maf.reactivespringbootstarter.service.CommonService;
import com.jmsoftware.maf.reactivespringbootstarter.service.impl.CommonServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
Expand Down Expand Up @@ -28,6 +32,12 @@ public void postConstruct() {
getClass().getSimpleName(), Integer.MIN_VALUE);
}

@Bean
public WebFluxConfiguration webFluxConfiguration() {
log.warn("Initial bean: {}", WebFluxConfiguration.class.getSimpleName());
return new WebFluxConfiguration();
}

@Bean
@ConditionalOnMissingBean
public MafConfiguration mafConfiguration() {
Expand All @@ -47,4 +57,22 @@ public MafProjectProperty mafProjectProperty() {
log.warn("Initial bean: {}", MafProjectProperty.class.getSimpleName());
return new MafProjectProperty();
}

@Bean
public IpHelper ipHelper(MafProjectProperty mafProjectProperty) {
log.warn("Initial bean: {}", IpHelper.class.getSimpleName());
return new IpHelper(mafProjectProperty);
}

@Bean
public CommonService commonService(MafProjectProperty mafProjectProperty) {
log.warn("Initial bean: {}", CommonServiceImpl.class.getSimpleName());
return new CommonServiceImpl(mafProjectProperty);
}

@Bean
public CommonController commonController(CommonService commonService) {
log.warn("Initial bean: {}", CommonController.class.getSimpleName());
return new CommonController(commonService);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jmsoftware.maf.apigateway.universal.configuration;
package com.jmsoftware.maf.reactivespringbootstarter.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.jmsoftware.maf.apigateway.universal.controller;
package com.jmsoftware.maf.reactivespringbootstarter.controller;

import com.jmsoftware.maf.apigateway.remoteapi.AuthCenterRemoteApi;
import com.jmsoftware.maf.apigateway.universal.service.CommonService;
import com.jmsoftware.maf.common.bean.ResponseBodyBean;
import com.jmsoftware.maf.common.domain.ValidationTestPayload;
import com.jmsoftware.maf.reactivespringbootstarter.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
Expand All @@ -28,20 +27,11 @@
@Api(tags = {"Common Controller"})
public class CommonController {
private final CommonService commonService;
private final AuthCenterRemoteApi authCenterRemoteApi;

@GetMapping("/app-info")
@ApiOperation(value = "/app-info", notes = "Retrieve application information")
public ResponseBodyBean<Map<String, Object>> applicationInformation() {
val data = commonService.getApplicationInfo();
final var roleListByUserId = authCenterRemoteApi.getRoleListByUserId(1L);
roleListByUserId
.map(getRoleListByUserIdResponseResponseBodyBean -> {
log.info("Response1: {}", getRoleListByUserIdResponseResponseBodyBean);
return getRoleListByUserIdResponseResponseBodyBean.getData();
})
.doOnNext(getRoleListByUserIdResponse -> log.info("Response2: {}", getRoleListByUserIdResponse.getRoleList()))
.subscribe();
return ResponseBodyBean.ofSuccess(data, "Succeed to retrieve app info.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jmsoftware.maf.apigateway.universal.configuration;
package com.jmsoftware.maf.reactivespringbootstarter.helper;

import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty;
import lombok.Getter;
Expand Down Expand Up @@ -29,7 +29,7 @@
@Getter
@Component
@RequiredArgsConstructor
public class ServerConfiguration implements ApplicationListener<WebServerInitializedEvent> {
public class IpHelper implements ApplicationListener<WebServerInitializedEvent> {
private static final String DEVELOPMENT_ENVIRONMENT = "development";
private final MafProjectProperty mafProjectProperty;
private int serverPort;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.jmsoftware.maf.apigateway.universal.service;
package com.jmsoftware.maf.reactivespringbootstarter.service;

import com.jmsoftware.maf.common.domain.ValidationTestPayload;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jmsoftware.maf.apigateway.universal.service.impl;
package com.jmsoftware.maf.reactivespringbootstarter.service.impl;

import com.jmsoftware.maf.apigateway.universal.service.CommonService;
import com.jmsoftware.maf.common.domain.ValidationTestPayload;
import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty;
import com.jmsoftware.maf.reactivespringbootstarter.service.CommonService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand Down

0 comments on commit 8d1f040

Please sign in to comment.