Skip to content

Server Configuration Example

Barry Beechinor edited this page Apr 15, 2014 · 4 revisions

The following configuration sets up an XDI endpoint backed by MongoDB at the relative path /graph:

<!-- MESSAGING TARGET at /graph -->


    <!-- This configuration will work for Single MongoDB Deployments plus Mongo  in Master Slave mode -->
<bean id="graphfactory1" class="xdi2.core.impl.json.mongodb.MongoDBJSONGraphFactory">
	<property name="host" value="localhost" />
</bean>

<bean id="graph1" factory-bean="graphfactory1" factory-method="openGraph" />

<bean name="/graph" class="xdi2.messaging.target.impl.graph.GraphMessagingTarget">
	<property name="graph" ref="graph1" />
</bean>

Alternate MongoDB Configuration using a ReplicaSet: http://docs.mongodb.org/manual/replication/

<!--  Replica Set Configuration -->

<bean id="graphFactoryReplica" class="xdi2.core.impl.json.mongodb.MongoDBJSONGraphFactory">
    <property name="host" value="${membergraph.graphfactory.host}" />
    <property name="replicaSet" ref="serverAddressList" />
    <property name="mongoClientOptions" ref="optionsBean"/>
</bean>

<!-- Three Member Replica Set: One Primary and 2 secondaries -->
<util:list id="serverAddressList" value-type="com.mongodb.ServerAddress">
    <ref bean="serverAddressA"/>
    <ref bean="serverAddressB"/>
    <ref bean="serverAddressC"/>
</util:list>

<bean id="serverAddressA" class="com.mongodb.ServerAddress">
    <constructor-arg index="0" value="${membergraph.replicaset.hostA}"/>
    <constructor-arg index="1" value="${membergraph.replicaset.portA}"/>
</bean>

<bean id="serverAddressB" class="com.mongodb.ServerAddress">
    <constructor-arg index="0" value="${membergraph.replicaset.hostB}"/>
    <constructor-arg index="1" value="${membergraph.replicaset.portB}"/>
</bean>

<bean id="serverAddressC" class="com.mongodb.ServerAddress">
    <constructor-arg index="0" value="${membergraph.replicaset.hostC}"/>
    <constructor-arg index="1" value="${membergraph.replicaset.portC}"/>
</bean>

<bean id="mongoClientOptionsFactory" class="xdi2.core.impl.json.mongodb.MongoClientOptionsFactory" >
    <property name="connectionsPerHost" value="${membergraph.mongoclient.connectionsPerHost}"/>
    <property name="connectTimeout" value="${membergraph.mongoclient.connectTimeout}"/>
    <property name="autoConnectRetry" value="${membergraph.mongoclient.autoConnectRetry}" />
    <property name="maxWaitTime" value="${membergraph.mongoclient.maxWaitTime}" />
    <property name="socketTimeout" value="${membergraph.mongoclient.socketTimeout}" />
    <property name="maxAutoConnectRetryTime" value="${membergraph.mongoclient.maxAutoConnectRetryTime}" />
    <property name="writeConcern" value="${membergraph.mongoclient.writeConcern}" />
    <property name="readPreference" value="${membergraph.mongoclient.readPreference}" />
</bean>

<bean id="optionsBean" factory-bean="mongoClientOptionsFactory" factory-method="createMongoClientOptions"/>

Sample Property File

#Replica Set Hosts/Ports
membergraph.replicaset.hostA=mongo-mgs-A-perf.respectnetwork.net
membergraph.replicaset.portA=27017
membergraph.replicaset.hostB=mongo-mgs-B-perf.respectnetwork.net
membergraph.replicaset.portB=27017
membergraph.replicaset.hostC=mongo-mgs-C-perf.respectnetwork.net
membergraph.replicaset.portC=27017

#MongoClient Options
membergraph.mongoclient.connectionsPerHost=20
#PRIMARY_READ_PREFERENCE = 1  PRIMARY_PREFERRED_READ_PREFERENCE = 2 SECONDARY_READ_PREFERENCE = 3 SECONDARY_PREFERRED_READ_PREFERENCE = 4 NEAREST_READ_PREFERENCE = 5
membergraph.mongoclient.readPreference=4
#UNACKNOWLEDGED = 1 : ACKNOWLEDGED = 2 : REPLICA_ACKNOWLEDGED = 3
membergraph.mongoclient.writeConcern=2
membergraph.mongoclient.connectTimeout=100
membergraph.mongoclient.autoConnectRetry=true
membergraph.mongoclient.maxWaitTime=100
membergraph.mongoclient.socketTimeout=100
membergraph.mongoclient.maxAutoConnectRetryTime=100
Clone this wiki locally