Neo4j connector in MuleSoft 4

 

In this tutorial we will demonstrate how to use neo4j connector in mule 4. But before that we should understand what is Graph Database.

 

Neo4j connector in Mule 4

 

Graph database is a database, that uses graph structure for storing data. It also treats relationship between data as equally important to the data itself. Graph databases are becoming popular database store. Since they store the relationship about data as well; traversing in graph database is easy and fast as compared to other database where you need to use expensive joins to traverse the data. Graph databases are also efficient in terms of searching the data irrespective of the size of the data set. They explore the data only within the starting points and leaves any data outside the search parameter.

 

Here is an example of a graph database. It considers the relationship various nodes as data also.

neo4j

Image credit: https://neo4j.com/developer/graph-database/

 

There are various important aspects in a graph database.

  • Node: Nodes are often used to represent entities. Nodes can contain properties that hold name-value pairs of data. Nodes can be assigned roles or types using one or more labels.
  • Relationship: A relationship connects two nodes and allows us to find related nodes of data. It has a source node and a target node that shows the direction of the arrow.
  • Label: To assign nodes to group or to categorize them
  • Properties: To define attributes of these entities as key-value properties.

Image credit: https://neo4j.com/developer/graph-database/

 

If you want to read more on the graph database please refer to the link below https://neo4j.com/developer/graph-database/

 

 

Prerequisite

 

  • Neo4j Graph database – Please use only neo4j 3.x database. Since the mulesoft neo4j connector version 3.0.4 has support for neo4j java driver 1.7.5, which supports only neo4j 3.x. If you use neo4.x with the current mulesoft neo4j connector you would get exceptions below.
“org.neo4j.driver.v1.exceptions.ServiceUnavailableException: Connection to the database terminated. This can happen due to network instabilities, or due to restarts of the database”
  • Neo4j Desktop – Install Neo4j desktop to browse and connect to database using a GUI, command line options.
  • MuleSoft Neo4j connector – Download the MuleSoft Neo4j connector version 3.0.4 from exchange. you can refer to https://docs.mulesoft.com/neo4j-connector/3.0/  for more details on the connector.

Steps

 

Install Neo4j 3.x community edition.

Download the Neo4j community edition graph database from and unzip the downloaded file https://neo4j.com/artifact.php?name=neo4j-community-3.5.22-windows.zip

Neo4j  connector in MuleSoft 4.x

 

Run the command “neo4j.bat console” to start the database

Neo4j  connector in MuleSoft 4.x

 

Download the Neo4j Desktop 4.1 from https://neo4j.com/download/ and install it. Connect to the local graph community database using “Add Database” as shown below in Neo4j desktop

Neo4j  connector in MuleSoft 4.x

 

Click on “Connect to remote DBMS” to connect to the neo4j database.

Neo4j  connector in MuleSoft 4.x

 

Enter the details of the database and click on Next as shown below.

Neo4j  connector in MuleSoft 4.x

 

Enter the details using “username/password” authentication option. Use default “neo4j” as username and password. Click on connect to connect to your local neo4j database.

 

Click on the Open button to open neo4j browser.

 

Enter the default credentials “neo4j” for username and password

 

It will prompt you to change the password. Otherwise you will not be able to do any operation with the database. Update the new password as below.

 

You are now connected to graph database with user “neo4j” and new password. You should be good to connect to the database from mulesoft now.

 

We will now show how to use neo4j connector in mule 4. Create a sample MuleSoft project and add the Neo4j connector from “Add Dependencies to Project” menu

Neo4j  connector in MuleSoft 4.x

 

Add the connection configuration as below and click on test connection. The connection test should be successful. If not, please check if your database has started or not.

Neo4j  connector in MuleSoft 4.x

 

There are various operations which you can perform using the connector for CRUD operations on nodes and execute CQL (command query language) in Neo4j graph database. Here is the detail below.

 

Create Node

 

use “create node” neo4j palette as below and payload as below

%dw 2.0
output application/json
---
{
  "name": "John",
  "location": "US"
}

Neo4j  connector in MuleSoft 4.x

 

You can verify the node and its properties in the Neo4j Desktop browser as below. we created two nodes with “Mulesy”, “India” and “John”, “US” as properties under the label “employee”.

 

 

Select Node

use “select node” neo4j palette as below and payload as below

%dw 2.0
output application/json
---
{
  "name": "John",
  "location": "US"
}

 

Neo4j  connector in MuleSoft 4.x

 

 

Delete Node

use “delete node” neo4j palette as below and payload as below

%dw 2.0
output application/json
---
{
  "name": "John",
  "location": "US"
}

Neo4j  connector in MuleSoft 4.x

 

 

Execute

You can execute CQL (cypher query language) using the Execute palette as below

 

CQL commands

"CREATE (a:ACTOR:PERSON { name:\"Tom Hanks\", born:1956 })"
"CREATE (john:Person {name: 'John'})"
"CREATE (joe:Person {name: 'Joe'})"
"CREATE (steve:Person {name: 'Steve'})"
"CREATE (sara:Person {name: 'Sara'})"
"CREATE (maria:Person {name: 'Maria'})"
"CREATE (john)-[:FRIEND]->(joe)-[:FRIEND]->(steve)"
"CREATE (john)-[:FRIEND]->(sara)-[:FRIEND]->(maria)"

You can verify the results in the Neo4j browser as below.

 

Sample Demo Applicationmulesy-neo4j

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments