Setting up bonsai-elasticsearch in Jhipster语言 - Heroku



部署到heroku我的Jhipster应用程序后,我想使用云elasticsearch(盆景)与Jhipster。Bonsai提供以下环境变量:

$BONSAI_URL 

如何正确地添加到application-prod.yml中?我一直在阅读文档,并试图将其设置为集群节点值和主机。但是我有点迷路了。任何建议都非常欢迎。

application-prod.yml

spring:
devtools:
    restart:
        enabled: false
    livereload:
        enabled: false
datasource:
    url: jdbc:mysql://localhost:3306/App?useUnicode=true&characterEncoding=utf8&useSSL=false
    name:
    username: root
    password:
    hikari:
        data-source-properties:
            cachePrepStmts: true
            prepStmtCacheSize: 250
            prepStmtCacheSqlLimit: 2048
            useServerPrepStmts: true
jpa:
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    database: MYSQL
    show_sql: false
    properties:
        hibernate.cache.use_second_level_cache: true
        hibernate.cache.use_query_cache: false
        hibernate.generate_statistics: false
        hibernate.cache.region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
data:
    elasticsearch:
        network:
            host: ${BONSAI_URL}
        cluster-name:  VLT
        cluster-nodes: localhost:9300
mail:
    host: smtp.sendgrid.net
    port: 587
    username: ${SENDGRID_USERNAME}
    password: ${SENDGRID_PASSWORD}
    protocol: smtp
    tls: false
    auth: true
    from: noreply@app.com
thymeleaf:
    cache: true
liquibase:
contexts: prod
server:
port: 8080
compression:
    enabled: true
    mime-types: text/html,text/xml,text/plain,text/css, application/javascript, application/json
    min-response-size: 1024

我添加了spring-boot-starter-data-jest库来构建脚本,build.gradle:

-    compile "org.springframework.boot:spring-boot-starter-data-elasticsearch"
+    compile "com.github.vanroy:spring-boot-starter-data-jest:2.2.0.RELEASE"

在应用类App.java中增加了ElasticsearchAutoConfiguration和ElasticsearchDataAutoConfiguration的排除:

@ComponentScan
+@EnableAutoConfiguration(exclude = {
+    ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class })
@EnableConfigurationProperties({ JHipsterProperties.class, LiquibaseProperties.class })
public class App {

和改变:

import org.elasticsearch.client.Client;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.EntityMapper;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.vanroy.springdata.jest.JestElasticsearchTemplate;
+import com.github.vanroy.springdata.jest.mapper.DefaultJestResultsMapper;
+import io.searchbox.client.JestClient;
@Configuration
public class ElasticSearchConfiguration {
  @Bean
-    public ElasticsearchTemplate elasticsearchTemplate(Client client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
-        return new ElasticsearchTemplate(client, new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build()));
+    public JestElasticsearchTemplate elasticsearchTemplate(JestClient client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) {
+        return new JestElasticsearchTemplate(client, new DefaultJestResultsMapper(
+                new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build())));
  }

然后我添加了配置参数,文件application.yml:

+    data:
+        elasticsearch:
+            properties:
+                path:
+                  home: target/elasticsearch
+                transport:
+                  tcp:
+                      connect_timeout: 120s
        jest:
+            readTimeout: 10000
             uri: ${SEARCHBOX_SSL_URL}

这适合我:

输入控制台heroku config:get BONSAI_URL -a YOUR_HEROKU APP NAME;

你会得到这样的结果:

https://xaawlsdv2z:dvt345cl1dk@jasm3ne-1113487.eu-west-1.bonsaisearch.net

in application-prod.yml:

data:
        elasticsearch:
            jest:
                uris: https://jasm3ne-1113487.eu-west-1.bonsaisearch.net:443
                read-timeout: 10000
                username: xaawlsdv2z
                password: dvt345cl1dk

最新更新