Ejemplo n.º 1
0
 public void start() throws Exception {
   Configuration conf = ConfigLoader.load("ingestor-cfg.xml");
   this.dbName = conf.getMongoDBName();
   List<ServerAddress> servers = new ArrayList<ServerAddress>(conf.getServers().size());
   for (ServerInfo si : conf.getServers()) {
     InetAddress inetAddress = InetAddress.getByName(si.getHost());
     servers.add(new ServerAddress(inetAddress, si.getPort()));
   }
   mongoClient = new MongoClient(servers);
   mongoClient.setWriteConcern(WriteConcern.SAFE);
 }
Ejemplo n.º 2
0
  @Override
  protected MongoClient createInstance() throws Exception {
    MongoClient mongo = initMongo();

    // 设定主从分离
    if (readSecondary) {
      mongo.setReadPreference(ReadPreference.secondaryPreferred());
    }
    // 设定写策略
    mongo.setWriteConcern(writeConcern);
    return mongo;
  }