• <i id='XWX6s'><tr id='XWX6s'><dt id='XWX6s'><q id='XWX6s'><span id='XWX6s'><b id='XWX6s'><form id='XWX6s'><ins id='XWX6s'></ins><ul id='XWX6s'></ul><sub id='XWX6s'></sub></form><legend id='XWX6s'></legend><bdo id='XWX6s'><pre id='XWX6s'><center id='XWX6s'></center></pre></bdo></b><th id='XWX6s'></th></span></q></dt></tr></i><div id='XWX6s'><tfoot id='XWX6s'></tfoot><dl id='XWX6s'><fieldset id='XWX6s'></fieldset></dl></div>

    <tfoot id='XWX6s'></tfoot>

        <bdo id='XWX6s'></bdo><ul id='XWX6s'></ul>
    1. <small id='XWX6s'></small><noframes id='XWX6s'>

    2. <legend id='XWX6s'><style id='XWX6s'><dir id='XWX6s'><q id='XWX6s'></q></dir></style></legend>

      1. Spring mongo 查询设置自定义超时

        Spring mongo queries set custom timeout(Spring mongo 查询设置自定义超时)

            <legend id='0kiaw'><style id='0kiaw'><dir id='0kiaw'><q id='0kiaw'></q></dir></style></legend>
          • <small id='0kiaw'></small><noframes id='0kiaw'>

              • <bdo id='0kiaw'></bdo><ul id='0kiaw'></ul>

                <i id='0kiaw'><tr id='0kiaw'><dt id='0kiaw'><q id='0kiaw'><span id='0kiaw'><b id='0kiaw'><form id='0kiaw'><ins id='0kiaw'></ins><ul id='0kiaw'></ul><sub id='0kiaw'></sub></form><legend id='0kiaw'></legend><bdo id='0kiaw'><pre id='0kiaw'><center id='0kiaw'></center></pre></bdo></b><th id='0kiaw'></th></span></q></dt></tr></i><div id='0kiaw'><tfoot id='0kiaw'></tfoot><dl id='0kiaw'><fieldset id='0kiaw'></fieldset></dl></div>
                    <tbody id='0kiaw'></tbody>
                  <tfoot id='0kiaw'></tfoot>
                  本文介绍了Spring mongo 查询设置自定义超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想降低 spring-mongo java 应用程序中的超时设置(如果无法访问数据库,查询应该在 300 毫秒后失败).

                  I would like to lower the timeout setting in my spring-mongo java application (the query should fail after 300 ms if the database is not accessible).

                  我试过这个配置:

                  @Configuration
                  public class MongoConfiguration {
                  
                  private String mongoUri = "mongodb://127.0.0.1:27017/myDb?connectTimeoutMS=300&socketTimeoutMS=300&waitQueueTimeoutMS=300&wtimeoutMS=300";
                  
                  @Bean
                  public MongoDbFactory mongoDbFactory() throws Exception {
                      Builder options = new MongoClientOptions.Builder().socketTimeout(300).connectTimeout(300).maxWaitTime(300);
                      return new SimpleMongoDbFactory(new MongoClientURI(mongoUri, options));
                  }
                  
                  @Bean
                  public MongoTemplate mongoTemplate() throws Exception {
                      MongoDbFactory mongoDbFactory = mongoDbFactory();
                      MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory);
                      return mongoTemplate;
                  }
                  
                  }
                  

                  但是 mongoUri 选项和构建器都会更改超时:查询仅在 30 000 毫秒后失败.

                  But the mongoUri options nor the builder change the timeout: the query fails only after 30 000ms.

                  我不确定应该覆盖哪个参数,也不确定如何正确执行.

                  I am not sure which parameter I should override nor the way to do it properly.

                  感谢您的帮助

                      <dependency>
                          <groupId>org.mongodb</groupId>
                          <artifactId>mongo-java-driver</artifactId>
                          <version>3.4.0</version>
                      </dependency>
                      <dependency>
                          <groupId>org.springframework.data</groupId>
                          <artifactId>spring-data-mongodb</artifactId>
                          <version>1.9.5.RELEASE</version>
                      </dependency>
                  

                  推荐答案

                  我在这里找到了答案:https://scalegrid.io/blog/understanding-mongodb-client-timeout-options/

                  @Bean
                  public MongoDbFactory mongoDbFactory() throws Exception {
                      MongoClientOptions.Builder optionsBuilder = MongoClientOptions.builder();
                      optionsBuilder.connectTimeout(300);
                      optionsBuilder.socketTimeout(300);
                      optionsBuilder.serverSelectionTimeout(300);
                      return new SimpleMongoDbFactory(new MongoClientURI(mongoUri, optionsBuilder));
                  }
                  

                  这篇关于Spring mongo 查询设置自定义超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                    <i id='7Kxrr'><tr id='7Kxrr'><dt id='7Kxrr'><q id='7Kxrr'><span id='7Kxrr'><b id='7Kxrr'><form id='7Kxrr'><ins id='7Kxrr'></ins><ul id='7Kxrr'></ul><sub id='7Kxrr'></sub></form><legend id='7Kxrr'></legend><bdo id='7Kxrr'><pre id='7Kxrr'><center id='7Kxrr'></center></pre></bdo></b><th id='7Kxrr'></th></span></q></dt></tr></i><div id='7Kxrr'><tfoot id='7Kxrr'></tfoot><dl id='7Kxrr'><fieldset id='7Kxrr'></fieldset></dl></div>
                  1. <tfoot id='7Kxrr'></tfoot>

                          <bdo id='7Kxrr'></bdo><ul id='7Kxrr'></ul>
                            <tbody id='7Kxrr'></tbody>

                            <small id='7Kxrr'></small><noframes id='7Kxrr'>

                            <legend id='7Kxrr'><style id='7Kxrr'><dir id='7Kxrr'><q id='7Kxrr'></q></dir></style></legend>