Skip to content

Using the MongoDB Data Adapter

stanzikratel edited this page Sep 5, 2014 · 1 revision

###Configuring Atom Hopper to use the MongoDB Data Adapter###

Note: The MongoDB Data Adapter is currently untested and is not production ready at this time. At this point, existing defects are being fixed with the MongoDB Data Adapter and no new features are being added. For production needs please use the Hibernate data adapter.

For better HTTP GET performance make sure to add an index on DateLastUpdated.

The MongoDB data adapter ships with Atom hopper version 1.1.0 and above. You can turn on the MongoDB data adapter easily following these steps:

  • Make sure MongoDB is installed and running where it can be seen by Atom Hopper. The default dbname is atomhopper
  • By default the configuration file application-context.xml will use a username/password to connect to MongoDB - you can remove this if you don't need it
  • Go to the location where the Atom Hopper configuration files are located, by default this path is: /etc/atomhopper
  • Edit the application-context.xml file so it looks similar to the following (edit as needed to suit your particular needs):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mongo="http://www.springframework.org/schema/data/mongo"
       xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <!-- MongoDB Connection -->
    <mongo:db-factory  id="mongoDbFactory"
			dbname="atomhopper"
            username="atomhopper"
            password="password"
            mongo-ref="mongo"/>

    <mongo:mongo replica-set="127.0.0.1:27017">
        <mongo:options connections-per-host="10"
                    slave-ok="true"/>
    </mongo:mongo>

    <bean name="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
    </bean>

    <bean name="mongodb-feed-publisher" class="org.atomhopper.mongodb.adapter.MongodbFeedPublisher">
        <property name="mongoTemplate" ref="mongoTemplate" />
    </bean>

    <bean name="mongodb-feed-source" class="org.atomhopper.mongodb.adapter.MongodbFeedSource">
        <property name="mongoTemplate" ref="mongoTemplate" />
    </bean>
</beans>

Note: You can also set the above configuration file to work with replica sets:

<mongo:mongo replica-set="192.168.1.100:27017,192.168.1.101:27017,192.168.1.102:27017"/>
  • Edit the atom-server.cfg.xml file (by default the file is located in: /etc/atomhopper) so it looks similar to the following (edit as needed to suit your particular needs):
<?xml version="1.0" encoding="UTF-8"?>
 
<atom-hopper-config xmlns="http://atomhopper.org/atom/hopper-config/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://atomhopper.org/atom/hopper-config/v1.0 ./../../config/atom-hopper-config.xsd">
    <defaults>
        <author name="Atom Hopper" />
    </defaults>
 
    <host domain="localhost:8080" />
 
    <workspace title="Testing Namespace" resource="/namespace/">
        <categories-descriptor reference="workspace-categories-descriptor" />
 
        <feed title="Testing Feed" resource="/feed">
            <publisher reference="mongodb-feed-publisher" />
            <feed-source reference="mongodb-feed-source" />
        </feed>
    </workspace>
</atom-hopper-config>

The important thing here is to ensure the following:

<publisher reference="mongodb-feed-publisher" />
<feed-source reference="mongodb-feed-source" />

Matches what is specified in the application-context.xml file.

<bean name="mongodb-feed-publisher" class="org.atomhopper.mongodb.adapter.MongodbFeedPublisher">
  <property name="mongoTemplate" ref="mongoTemplate" />
</bean>
<bean name="mongodb-feed-source" class="org.atomhopper.mongodb.adapter.MongodbFeedSource">
  <property name="mongoTemplate" ref="mongoTemplate" />
</bean>

If Atom Hopper is currently running you will need to restart it for the changes to take effect.

For each feed you configure Atom Hopper will create a corresponding collection in MongoDB. So if you have the following feeds:

http://localhost:8080/namespace/feed1/
http://localhost:8080/namespace/feed2/
http://localhost:8080/cloud/servers/status/

Given the above, you will end up with the following collections in MongoDB:

  • namespace.feed1
  • namespace.feed2
  • cloud.servers.status