Spring Reactive Neo4j



Neo4j is a Graph database which means, simply, that rather than data being stored in tables or collections it is stored as nodes and relationships between nodes. In Neo4j both nodes. If you have multiple transactions in the same thread or the same reactive stream, SDN/RX will take care that you will read your own writes. It makes use of the bookmarking mechanism provided. The Spring Data Neo4j Reactive library is new and a planned successor to the Spring Data Neo4j offering. Its feature benefit is the capability and support for reactive transactions, though there are other improvements and additions, as well.

Hello friends!!! Here we are going to discuss Spring Boot with NoSQL, how Spring Boot provide the support for NoSQL technologies and how to use into Spring Boot Application. NoSQL is a non-relational database management systems, different from traditional relational database management systems in some significant ways.

Reactive

NoSQL is nothing but it is database without support of SQL queries unlike traditional databases MySQL, DB2, Oracle etc. Spring Data provides additional projects that help you access a variety of NoSQL technologies including MongoDB, Neo4J, Elasticsearch, Solr, Redis, Gemfire, Couchbase and Cassandra. Spring Boot provides auto-configuration for Redis, MongoDB, Neo4j, Elasticsearch, Solr and Cassandra.

Spring Boot with NoSQL

1. MongoDB

MongoDB is an open-source NoSQL document database that uses a JSON-like schema instead of traditional table-based relational data. Spring Boot offers several conveniences for working with MongoDB, including the spring-boot-starter-data-mongodb ‘Starter’. Spring Data includes repository support for MongoDB.

Spring Boot offers auto-configuration for Embedded Mongo. To use it in your Spring Boot application add a dependency on de.flapdoodle.embed:de.flapdoodle.embed.mongo. The port that Mongo will listen on can be configured using the spring.data.mongodb.port property. To use a randomly allocated free port use a value of zero. The MongoClient created by MongoAutoConfiguration will be automatically configured to use the randomly allocated port.

1.1 Connecting to a MongoDB database

Spring Data Mongo provides a MongoTemplate class that is very similar in its design to Spring’s JdbcTemplate. As with JdbcTemplate Spring Boot auto-configures a bean for you to simply inject:

For MongoDB Full Example Click Here

2. Neo4j

Neo4j is an open-source NoSQL graph database that uses a rich data model of nodes related by first class relationships which is better suited for connected big data than traditional rdbms approaches. Spring Boot offers several conveniences for working with Neo4j, including the spring-boot-starter-data-neo4j ‘Starter’.

You can configure the user and credentials to use via the spring.data.neo4j.* properties:

2.1 Connecting to a Neo4j database

By default the instance will attempt to connect to a Neo4j server using localhost:7474

2.2 Using the embedded mode

If you add org.neo4j:neo4j-ogm-embedded-driver to the dependencies of your application, Spring Boot will automatically configure an in-process embedded instance of Neo4j that will not persist any data when your application shuts down. You can explicitly disable that mode using spring.data.neo4j.embedded.enabled=false.

2.3 Spring Data Neo4j repositories

Spring Data includes repository support for Neo4j. You can customize entity scanning locations using the @NodeEntityScan annotation.

3. Redis

Redis is a cache, message broker and richly-featured key-value store. Spring Boot offers basic auto-configuration for the Jedis client library and abstractions on top of it provided by Spring Data Redis. There is a spring-boot-starter-data-redis ‘Starter’ for collecting the dependencies in a convenient way.

You can inject an auto-configured RedisConnectionFactory, StringRedisTemplate or vanilla RedisTemplate instance as you would any other Spring Bean. By default the instance will attempt to connect to a Redis server using localhost:6379.

4. Gemfire

Neo4j Spring Data

Spring Data Gemfire provides convenient Spring-friendly tools for accessing the Pivotal Gemfire data management platform. There is a spring-boot-starter-data-gemfire ‘Starter’ for collecting the dependencies in a convenient way. There is currently no auto-configuration support for Gemfire, but you can enable Spring Data Repositories with a single annotation (@EnableGemfireRepositories).

5. Solr

Apache Solr is a search engine. Spring Boot offers basic auto-configuration for the Solr 5 client library and abstractions on top of it provided by Spring Data Solr. There is a spring-boot-starter-data-solr ‘Starter’ for collecting the dependencies in a convenient way.

You can inject an auto-configured SolrClient instance as you would any other Spring bean. By default the instance will attempt to connect to a server using localhost:8983/solr:

5.1 Spring Data Solr repositories

Spring Data includes repository support for Apache Solr.

6. Elasticsearch

Elasticsearch is an open source, distributed, real-time search and analytics engine. Spring Boot offers basic auto-configuration for the Elasticsearch and abstractions on top of it provided by Spring Data Elasticsearch. There is a spring-boot-starter-data-elasticsearch ‘Starter’ for collecting the dependencies in a convenient way. Spring Boot also supports Jest.

Neo4j Application

6.1 Connecting to Elasticsearch using Spring Data

You can inject an auto-configured ElasticsearchTemplate or Elasticsearch Client instance as you would any other Spring Bean. By default the instance will embed a local in-memory server (a Node in Elasticsearch terms) and use the current working directory as the home directory for the server.
you can switch to a remote server by setting spring.data.elasticsearch.cluster-nodes to a comma-separated ‘host:port’ list.

Spring Reactive Neo4j

Spring Data includes repository support for Elasticsearch.

6.2 Connecting to Elasticsearch using Jest

If you have Jest on the classpath, you can inject an auto-configured JestClient targeting localhost:9200 by default.

Spring Reactive Neo4j Group

7. Cassandra

Cassandra is an open source, distributed database management system designed to handle large amounts of data across many commodity servers. Spring Boot offers auto-configuration for Cassandra and abstractions on top of it provided by Spring Data Cassandra. There is a spring-boot-starter-data-cassandra ‘Starter’ for collecting the dependencies in a convenient way.

7.1 Connecting to Cassandra

Spring Reactive Neo4j System

You can inject an auto-configured CassandraTemplate or a Cassandra Session instance as you would with any other Spring Bean. The spring.data.cassandra.* properties can be used to customize the connection.

8. Couchbase

Couchbase is an open-source, distributed multi-model NoSQL document-oriented database that is optimized for interactive applications. Spring Boot offers auto-configuration for Couchbase and abstractions on top of it provided by Spring Data Couchbase. There is a spring-boot-starter-data-couchbase ‘Starter’ for collecting the dependencies in a convenient way.

The spring.couchbase.* properties can be used to customize the connection. Generally you will provide the bootstrap hosts, bucket name and password:

Spring Data includes repository support for Couchbase. ou can inject an auto-configured CouchbaseTemplate instance.

Summary

Here we have discussed some detail about NoSQL database with Spring Boot. Spring Boot Provide major support and auto configuration for connect to NoSQl databases.

Happy Spring Boot Learning!!!

Reference
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/

Spring Boot Related Topics

  1. Introduction to Spring Boot