Grails 3安装application.yml制作mongodb [英] Grails 3 Setup application.yml production mongodb

查看:139
本文介绍了Grails 3安装application.yml制作mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 开发:
grails:$ b $如何设置在生产中使用mongodb的使用connectionstring b mongodb:
connectionString:mongodb:// localhost:27017 / fanfest

产品:
dataSource:
dbCreate:更新
url:jdbc :h2:./ prodDb; MVCC = TRUE; LOCK_TIMEOUT = 10000; DB_CLOSE_ON_EXIT = FALSE
属性:
jmxEnabled:true
initialSize:5
maxActive:50
minIdle :5
maxIdle:25
maxWait:10000
maxAge:600000
timeBetweenEvictionRunsMillis:5000
minEvictableIdleTimeMillis:60000
validationQuery:SELECT 1
validationQueryTimeout :3
validationInterval:15000
testOnBorrow:true
testWhileIdle:true
testOnReturn:false
jdbcInterceptors:ConnectionState
defaultTransactionIsolation:2#TRANSACTION_READ_COMMITTED

使用Grails 3版本。能够在开发环境中与mongodb连接。请提供一些建议,以在生产环境中设置mongodb。

解决方案

您目前正在开发指向mongo实例。生产配置指向内存H2数据库。如果你想为你的生产环境配置一个mongo数据库,我建议你看看

 生产{
grails {
mongodb {
connectionString = mongodb:// localhost:27017 / PROD_fanfest
}
}
}

请注意我使用了您的开发网址,但更改了表名,因为我建议您将开发数据库和生产数据库分开。将生产数据源配置为使用Mongo非常简单。在使用入门

以下配置选项的相关信息:

  options {
connectionsPerHost = 10 //每个主机允许的最大连接数
threadsAllowedToBlockForConnectionMultiplier = 5
maxWaitTime = 120000 //连接阻塞线程的最大等待时间。
connectTimeout = 0 //连接超时以毫秒为单位。 0 ==无限
socketTimeout = 0 //套接字超时。 0 ==无限
socketKeepAlive = false //是否启用套接字保持活动状态
writeConcern = new com.mongodb.WriteConcern(0,0,false)//指定服务器数量等待写操作和异常提升行为
sslEnabled = false //指定驱动程序是否应该使用到Mongo的SSL连接
socketFactory = ... //指定用于创建连接的SocketFactory
}


How to set the use connectionstring which usess mongodb in production.

development:
        grails:
            mongodb:
                connectionString: "mongodb://localhost:27017/fanfest"

    production:
        dataSource:
            dbCreate: update
            url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
            properties:
                jmxEnabled: true
                initialSize: 5
                maxActive: 50
                minIdle: 5
                maxIdle: 25
                maxWait: 10000
                maxAge: 600000
                timeBetweenEvictionRunsMillis: 5000
                minEvictableIdleTimeMillis: 60000
                validationQuery: SELECT 1
                validationQueryTimeout: 3
                validationInterval: 15000
                testOnBorrow: true
                testWhileIdle: true
                testOnReturn: false
                jdbcInterceptors: ConnectionState
                defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

Working with Grails 3 version. Able to connect with mongodb in development environment. Kindly provide some suggestions to set the mongodb in production environment.

You currently have development pointing at a mongo instance. The production configuration is pointed at the in memory H2 database. If you would like to configure a mongo database for your production environment may I suggest you take a look at Getting Started guide for Mongo and GORM.

In the production section of your configuration file you can use the connection string parameter as follows:

production {    
    grails {
        mongodb {
            connectionString = "mongodb://localhost:27017/PROD_fanfest"
        }
    }
}

Please note I have used your development URL but changed the table name since I recommend you keep the development database and production database separate. Configuring production datasource to use Mongo is that easy. There are more configuration options described in the Getting Started documentation.

Relevant information on configuring options below:

options {
    connectionsPerHost = 10 // The maximum number of connections allowed per host
    threadsAllowedToBlockForConnectionMultiplier = 5
    maxWaitTime = 120000 // Max wait time of a blocking thread for a connection.
    connectTimeout = 0 // The connect timeout in milliseconds. 0 == infinite
    socketTimeout = 0 // The socket timeout. 0 == infinite
    socketKeepAlive = false // Whether or not to have socket keep alive turned on
    writeConcern = new com.mongodb.WriteConcern(0, 0, false) // Specifies the number of servers to wait for on the write operation, and exception raising behavior
    sslEnabled = false // Specifies if the driver should use an SSL connection to Mongo
    socketFactory = … // Specifies the SocketFactory to use for creating connections
}

这篇关于Grails 3安装application.yml制作mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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