Reputation: 131
I am building a neo4j ogm service using ogm in java. I need to connect to 2 neo4j server from my service to handle failover and replication. Is it possible to create multiple session each towards different neo4j server from one ogm service.
Upvotes: 2
Views: 481
Reputation: 15086
You can, in theory, create multiple SessionFactory
instances, pointing to different database instances and perform each operation on both. Just use Java configuration instead of property file (this is true for OGM only, SDN would not be that simple).
There are multiple things to look out for:
you can't rely on the the auto generated ids as they could be different on each database instance
when writing to 2 instances, write to first instances may (for various reasons - network issues, latencies, concurrency etc..) succeed and write to second may fail, or vice versa - your code would need to handle that somehow
concurrency in general - queries dependent on state of the database may behave differently on the two instances because of one of them received more updates than the other (the second is "behind")
Because of all these reasons I wouldn't recommend such solution at all.
You would be better off with either Neo4j's HA or causal cluster. See the website regarding licensing.
Upvotes: 1