Skip to content

Commit

Permalink
perf($starter): integrate with spring-boot-starter-data-elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Feb 20, 2022
1 parent c1a57db commit 0f4dff5
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ spring:

logging:
config: classpath:logback-configuration/logback-${spring.profiles.active}.xml
level:
org.springframework.data.elasticsearch.client.WIRE: DEBUG

maf:
project-properties:
Expand Down
4 changes: 4 additions & 0 deletions auth-center/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ spring:
max-idle: 10
max-wait: -1ms
min-idle: 0
elasticsearch:
uris:
- http://maf-elasticsearch:9200
username: elastic
password: maf@elasticsearch
quartz:
job-store-type: JDBC
jdbc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ spring:
max-idle: 10
max-wait: -1ms
min-idle: 0
elasticsearch:
uris:
- http://localhost:9200
username: elastic
password: maf@elasticsearch
quartz:
job-store-type: JDBC
jdbc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ spring:
max-idle: 10
max-wait: -1ms
min-idle: 0
elasticsearch:
uris:
- http://maf-elasticsearch:9200
username: elastic
password: maf@elasticsearch
quartz:
job-store-type: JDBC
jdbc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ spring:
max-idle: 10
max-wait: -1ms
min-idle: 0
elasticsearch:
uris:
- http://maf-elasticsearch:9200
username: elastic
password: maf@elasticsearch
quartz:
job-store-type: JDBC
jdbc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ spring:
max-idle: 10
max-wait: -1ms
min-idle: 0
elasticsearch:
uris:
- http://maf-elasticsearch:9200
username: elastic
password: maf@elasticsearch
quartz:
job-store-type: JDBC
jdbc:
Expand Down
4 changes: 4 additions & 0 deletions maf-mis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions spring-cloud-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
<artifactId>spring-boot-starter-data-redis</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.jmsoftware.maf.springcloudstarter.controller.HttpApiResourceRemoteApiController;
import com.jmsoftware.maf.springcloudstarter.controller.RedirectController;
import com.jmsoftware.maf.springcloudstarter.database.MyBatisPlusConfiguration;
import com.jmsoftware.maf.springcloudstarter.elasticsearch.ElasticsearchConfiguration;
import com.jmsoftware.maf.springcloudstarter.filter.AccessLogFilter;
import com.jmsoftware.maf.springcloudstarter.helper.HttpApiScanHelper;
import com.jmsoftware.maf.springcloudstarter.helper.IpHelper;
Expand Down Expand Up @@ -66,6 +67,7 @@
WebMvcConfiguration.class,
MyBatisPlusConfiguration.class,
RedisConfiguration.class,
ElasticsearchConfiguration.class,
WebSecurityConfiguration.class,
RestTemplateConfiguration.class,
AsyncConfiguration.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.context.request.async.CallableProcessingInterceptor;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Objects;

import static org.springframework.web.cors.CorsConfiguration.ALL;

/**
Expand All @@ -29,7 +26,7 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
* can be cached by clients. By default this is set to 1800 seconds (30 minutes).
*/
private static final long MAX_AGE_SECS = 3600;
private final AsyncConfigurer asyncConfigurer;
private final ThreadPoolTaskExecutor threadPoolTaskExecutor;
private final CallableProcessingInterceptor callableProcessingInterceptor;

/**
Expand All @@ -52,7 +49,7 @@ public void addCorsMappings(CorsRegistry registry) {
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(360000)
.setTaskExecutor((AsyncTaskExecutor) Objects.requireNonNull(this.asyncConfigurer.getAsyncExecutor()))
.setTaskExecutor(threadPoolTaskExecutor)
.registerCallableInterceptors(this.callableProcessingInterceptor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.jmsoftware.maf.springcloudstarter.elasticsearch;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.time.LocalDateTime;

/**
* Description: Book, change description here.
*
* @author 钟俊 (za-zhongjun), email: jun.zhong@zatech.com, date: 2/20/2022 1:40 PM
*/
@Data
@Document(indexName = "books")
public class Book {
/**
* The Id.
*/
@Id
private String id;
/**
* The Title.
*/
@Field(type = FieldType.Text, name = "name")
private String name;
/**
* The Summary.
*/
@Field(type = FieldType.Text)
private String summary;
/**
* The Publishing date.
*/
@Field(type = FieldType.Date, name = "publishDate", format = {}, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'")
private LocalDateTime publishingDate;
/**
* The Price.
*/
@Field(type = FieldType.Double, name = "price")
private double price;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.jmsoftware.maf.springcloudstarter.elasticsearch;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;

/**
* Description: BookRepository, change description here.
*
* @author 钟俊 (za-zhongjun), email: jun.zhong@zatech.com, date: 2/20/2022 2:06 PM
**/
public interface BookRepository extends ElasticsearchRepository<Book, String> {
/**
* Find by name and price list.
*
* @param name the name
* @param price the price
* @return the list
*/
List<Book> findByNameAndPrice(String name, Integer price);

/**
* Find by name page.
*
* @param name the name
* @param pageable the pageable
* @return the page
*/
@Query("{\"match\": {\"name\": {\"query\": \"?0\"}}}")
Page<Book> findByName(String name, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.jmsoftware.maf.springcloudstarter.elasticsearch;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchProperties;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

import javax.annotation.PostConstruct;

/**
* Description: ElasticsearchConfiguration, change description here.
*
* @author 钟俊 (za-zhongjun), email: jun.zhong@zatech.com, date: 2/19/2022 11:38 PM
* @see
* <a href='https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/'>Spring Data Elasticsearch - Reference Documentation</a>
* @see
* <a href='https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.clients.logging'>Client Logging</a>
**/
@Slf4j
@RequiredArgsConstructor
@EnableElasticsearchRepositories
@ConditionalOnClass({AbstractElasticsearchConfiguration.class, RestHighLevelClient.class})
public class ElasticsearchConfiguration {
private final ElasticsearchProperties elasticsearchProperties;

@PostConstruct
public void init() {
log.warn("ElasticsearchConfiguration init. URIs: {}", elasticsearchProperties.getUris());
}
}

0 comments on commit 0f4dff5

Please sign in to comment.