在Jhipster - Heroku中设置盆景弹性搜索 [英] Setting up bonsai-elasticsearch in Jhipster - Heroku

查看:221
本文介绍了在Jhipster - Heroku中设置盆景弹性搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在部署到heroku我的Jhipster应用后,我想使用JSON弹性云搜索(Bonsai)。 Bonsai提供了以下env变量:

  $ BONSAI_URL 

这是如何在application-prod.yml中正确添加的?
我一直在阅读文档并尝试将其设置为集群节点值和主机。但我有点失落。



application-prod.yml

  spring:
devtools:
重新启动:
启用:false
livereload:
启用:false
数据源:
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
数据库:MYSQL
show_sql:false
属性:
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.eh cache.SingletonEhCacheRegionFactory
data:
elasticsearch:
network:
host:$ {BONSAI_URL}
cluster-name:VLT
cluster-nodes:localhost: 9300
邮箱:
主机:smtp.sendgrid.net
端口:587
用户名:$ {SENDGRID_USERNAME}
密码:$ {SENDGRID_PASSWORD}
协议:smtp
tls:false
auth:true
from:noreply@app.com

thymeleaf:
缓存:true

liquibase:
上下文:prod

服务器:
端口:8080
压缩:
启用: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:

   -  compileorg.springframework.boot:spring-boot-starter-data-elasticsearc h
+ compilecom.github.vanroy:spring-boot-starter-data-jest:2.2.0.RELEASE

在应用程序类 App.java 中添加了ElasticsearchAutoConfiguration和ElasticsearchDataAutoConfiguration的排除项:

<$ $ {code> @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(客户端客户端,Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder){
- return新的ElasticsearchTemplate(客户端,新的CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build()));
+ public JestElasticsearchTemplate elasticsearchTemplate(JestClient客户端,Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder){
+返回新的JestElasticsearchTemplate(客户端,新的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}


After deploying to heroku my Jhipster app, I want to use cloud elasticsearch (Bonsai) with JHipster. Bonsai provides following env variable:

$BONSAI_URL 

How is this properly added in application-prod.yml? I`ve been reading the docs and trying too set it as cluster-nodes value and as host. But i'm a bit lost. Any tips are more than welcome.

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

解决方案

I added spring-boot-starter-data-jest library to build script, build.gradle:

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

Added exclude for ElasticsearchAutoConfiguration and ElasticsearchDataAutoConfiguration in application class App.java:

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

And changed:

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())));
  }

Then I added configuraiton parameters, file application.yml:

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

这篇关于在Jhipster - Heroku中设置盆景弹性搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆