-
Notifications
You must be signed in to change notification settings - Fork 52
Using Multiple Databases with Multiple Feeds
With the a supported data adapter you can setup Atom Hopper to use multiple databases per feed. What this means is that you can have the following scenario:
http://localhost/myfeed/events/ = maps to PostgreSQL Server 1
http://localhost/something/alerts/ = maps to MySQL Server 1
http://localhost/hello/world/ = maps to PostgreSQL Server 2
In the situation above you have three unique feeds, each mapped to a different database server. Since the Atom Hopper supports many types of data adapters, using the Hibernate one you only need to modify two files in Atom Hopper to achieve the above scenario.
- atom-server.cfg.xml this file allows you to setup a single feed or multiple feed configurations
- application-context.xml this file is where you setup the configuration to connect to a single or multiple database backends
Note: Please be aware that currently existing defects are being fixed with the hibernate Data Adapter and no new features are being added.
If I want to set up the above scenario my two configuration files will look like the following:
atom-server.cfg.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<atom-hopper-config xmlns="http://atomhopper.org/atom/hopper-config/v1.0">
<defaults>
<author name="author"/>
</defaults>
<host domain="localhost"/>
<workspace resource="/myfeed/" title="My Feed">
<feed resource="/events/" title="Events">
<feed-source reference="hibernate-feed-source-pg1"/>
<publisher reference="hibernate-feed-publisher-pg1"/>
</feed>
</workspace>
<workspace resource="/something/" title="Something">
<feed resource="/alerts/" title="Alerts">
<feed-source reference="hibernate-feed-source-mysql1"/>
<publisher reference="hibernate-feed-publisher-mysql1"/>
</feed>
</workspace>
<workspace resource="/hello/" title="Hello">
<feed resource="/world/" title="World">
<feed-source reference="hibernate-feed-source-pg2"/>
<publisher reference="hibernate-feed-publisher-pg2"/>
</feed>
</workspace>
</atom-hopper-config>
You can see I setup the three unique feeds and then using the feed-source and publisher I'm mapping it to the correct spot in the application-context.xml file.
application-context.xml
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- Hibernate -->
<bean name="feed-repository-bean1" class="org.atomhopper.hibernate.HibernateFeedRepository">
<constructor-arg>
<map>
<!-- Start PostgreSQL Config -->
<entry key="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<entry key="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<entry key="hibernate.connection.url" value="jdbc:postgresql://127.0.0.1:5432/atomhopper" />
<entry key="hibernate.connection.username" value="postgres" />
<entry key="hibernate.connection.password" value="password" />
<!-- End PostgreSQL Config -->
<entry key="hibernate.hbm2ddl.auto" value="update" />
</map>
</constructor-arg>
</bean>
<bean name="feed-repository-bean2" class="org.atomhopper.hibernate.HibernateFeedRepository">
<constructor-arg>
<map>
<!-- Start MySQL Config -->
<entry key="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<entry key="hibernate.connection.url" value="jdbc:mysql://127.1.1.1:8889/atomhopper?createDatabaseIfNotExist=true" />
<entry key="hibernate.connection.username" value="root" />
<entry key="hibernate.connection.password" value="root" />
<!-- End MySQL Config -->
<entry key="hibernate.hbm2ddl.auto" value="update" />
</map>
</constructor-arg>
</bean>
<bean name="feed-repository-bean3" class="org.atomhopper.hibernate.HibernateFeedRepository">
<constructor-arg>
<map>
<!-- Start PostgreSQL Config -->
<entry key="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<entry key="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<entry key="hibernate.connection.url" value="jdbc:postgresql://127.2.2.2:5432/atomhopper" />
<entry key="hibernate.connection.username" value="postgres" />
<entry key="hibernate.connection.password" value="password" />
<!-- End PostgreSQL Config -->
<entry key="hibernate.hbm2ddl.auto" value="update" />
</map>
</constructor-arg>
</bean>
<bean name="hibernate-feed-source-pg1" class="org.atomhopper.hibernate.adapter.HibernateFeedSource">
<property name="feedRepository" ref="feed-repository-bean1" />
</bean>
<bean name="hibernate-feed-publisher-pg1" class="org.atomhopper.hibernate.adapter.HibernateFeedPublisher">
<property name="feedRepository" ref="feed-repository-bean1" />
</bean>
<bean name="hibernate-feed-source-mysql1" class="org.atomhopper.hibernate.adapter.HibernateFeedSource">
<property name="feedRepository" ref="feed-repository-bean2" />
</bean>
<bean name="hibernate-feed-publisher-mysql1" class="org.atomhopper.hibernate.adapter.HibernateFeedPublisher">
<property name="feedRepository" ref="feed-repository-bean2" />
</bean>
<bean name="hibernate-feed-source-pg2" class="org.atomhopper.hibernate.adapter.HibernateFeedSource">
<property name="feedRepository" ref="feed-repository-bean3" />
</bean>
<bean name="hibernate-feed-publisher-pg2" class="org.atomhopper.hibernate.adapter.HibernateFeedPublisher">
<property name="feedRepository" ref="feed-repository-bean3" />
</bean>
</beans>
This sets up three databases which are then mapped to the three feeds. In this case I have two PostgreSQL databases and one MySQL database. If you're using multiple databases, make sure that your Apache Tomcat (or whatever application server your using) has the JDBC drivers in the classpath. For Apache Tomcat you can put the JDBC drivers for PostgreSQL and MySQL in the lib folder.