Overview
Anypoint Connector for Neo4J provides the capability of execute CQL statements and run basic operations (such as create, update, delete, select nodes) against a Neo4J Graph DB instance.
See:
MuleSoft maintains this connector under the Connector Support Policy - Select.
This document assumes that you are familiar with Mule, Anypoint Connectors, Anypoint Studio, Mule Concepts, and Global Elements.
For hardware and software requirements, see the Neo4J Connector Release Notes.
How to Install
You can install the connector in Anypoint Studio using the instructions in Installing a Connector from Anypoint Exchange.
If you are upgrading from a previous version of the connector, a small popup appears in the bottom right corner of Anypoint Studio with the "Updates Available" message. Click the popup and follow the prompts to install the latest version.
Connector Namespace and Schema
When designing your application in Anypoint Studio, when you drag the connector from the palette onto the Anypoint Studio canvas, Studio automatically populates the XML code with the connector namespace and schema location.
-
Namespace:
http://www.mulesoft.org/schema/mule/neo4j
-
Schema Location:
http://www.mulesoft.org/schema/mule/neo4j/current/mule-neo4j.xsd
If you are manually coding the Mule application in Studio’s XML editor or another text editor, define the namespace and schema location in the header of your Configuration XML, inside the <mule> tag.
|
1
2
3
4
5
6
7
8
9
10
11
12
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:connector="http://www.mulesoft.org/schema/mule/neo4j"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/neo4j
http://www.mulesoft.org/schema/mule/neo4j/current/mule-neo4j.xsd">
<!-- put your global configuration elements and flows here -->
</mule>
Use current in the schema path. Studio interprets this to the current Mule version.
|
Maven Dependency Information
For Maven dependency management, include this XML snippet in your pom.xml
file.
1
2
3
4
5
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-module-neo4j</artifactId>
<version>2.0.0</version>
</dependency>
Inside the <version>
tags, put the desired version number, the word RELEASE
for the latest release, or SNAPSHOT
for the latest available version.
How to Configure
Place the connector in your flow as applicable for your use case.
To use the Neo4J connector in your Mule application, you must configure a global Neo4J element that can be used by the Neo4J connector. The Neo4J connector provides the following global configuration, requiring the following information:
Field | Description |
---|---|
Username |
Enter the username to log in with. |
Password |
Enter the corresponding password. |
BOLT URL |
Bolt endpoint. |
REST URL |
Rest endpoint URL (works with HTTP or HTTPS). |
Operations
Name | Description |
---|---|
Execute |
Execute any CQL statement against DB. |
Create Node |
Create a node with a specific initial label. Optionally, properties for the node can be added. |
Select Nodes |
Query nodes with a specific label. Optionally, properties used as filter can be provided. |
Update Nodes |
Modified properties for one or multiple nodes with a specific label. Optional Properties can be added as search filter criteria. |
Delete Nodes |
Delete one or multiples nodes based on a specific label. This lets you delete nodes with inbound/outbound relationships. Optional Properties can be added as search filter criteria. |
Neo4J’s connector basic operations can filter nodes by only one label in its query. If you want to filter in a query by multiple labels, please use Execute operation with a proper CQL statement. A multi-label query example is provided here |
For a full list of operations for any version of the connector, see the Neo4J Connector Reference.
Metadata
Neo4J connector metadata is based on the following premises:
-
Labels listed on operations are all the labels that are instanced in DB.
-
DB has to have constraints defined for its nodes:
-
Unique property constraints
-
Property existance constraints
-
At least one node with constraints values has to be defined in DB
-
Common Use Cases
Node Basic CRUD
-
Create a new Mule Project in Anypoint Studio and set your Neo4J environment properties in
src/main/resources/mule-app.properties
.1 2 3 4
config.username=<USERNAME> config.password=<PASSWORD> config.boltUrl=<BOLT_URL_ENDOPOINT> config.restUrl=<REST_URL_ENDPOINT>
-
Drag an HTTP connector onto the canvas and configure it with the default values.
-
Drag a Transform Message onto the canvas and create a flowVar called 'params' with the following code:
1 2 3 4 5 6 7
%dw 1.0 %output application/java --- { "name":"Tom Hanks", "born": 1956 }
-
Drag the Neo4J connector onto the canvas and configure a new Global Element according to the table below:
Parameter Value Username
${neo4j.username}
Password
${neo4j.password}
BOLT URL
${neo4j.boltUrl}
REST URL
${neo4j.restUrl}
<neo4j:config name="Neo4j__Basic_Authentication" username="${neo4j.username}" password="${neo4j.password}" boltUrl="${neo4j.boltUrl}" restUrl="${neo4j.restUrl}" doc:name="Neo4j: Basic Authentication"/>
-
In the Properties Editor, configure:
Parameter Value Display Name
Create node
Connector Configuration
Neo4j__Basic_Authentication
Operation
Create node
Label
Person
Parameters Reference
#[payload]
Note: Click Test Connection to confirm that Mule can connect with the Neo4J instance. If the connection is successful, click OK to save the configuration. Otherwise, review or correct any invalid parameters and test again.
-
-
Drag a Neo4J connector onto the canvas, in the Properties Editor, configure the parameters:
Parameter Value Operation
Select nodes
Label
Person
-
Drag a Neo4J connector onto the canvas, in the Properties Editor, configure the parameters:
Parameter Value Operation
Delete nodes
Label
Person
-
Drag an Object to JSON onto the canvas.
-
Save the changes and deploy the project as a Mule Application. Open a browser and make a request to the following URL:
http://localhost:8081/CRUD
If the node was successfully created and deleted, information should be displayed in a JSON format:
[{"a":{"born":1956,"name":"Tom Hanks"}}]
Create a node with multiple labels
-
Create a new Mule Project in Anypoint Studio and set your Neo4J environment properties in
src/main/resources/mule-app.properties
.1 2 3 4
config.username=<USERNAME> config.password=<PASSWORD> config.boltUrl=<BOLT_URL_ENDOPOINT> config.restUrl=<REST_URL_ENDPOINT>
-
Drag an HTTP connector onto the canvas and configure it with the default values.
-
Drag a Transform Message onto the canvas and create two flowVars with the following code:
-
FlowVar-create
1 2 3 4
%dw 1.0 %output application/java --- "CREATE (a:ACTOR:PERSON { name:\"Tom Hanks\", born:1956 })"
-
FlowVar-select
1 2 3 4
%dw 1.0 %output application/java --- "MATCH (a:ACTOR:PERSON) RETURN a"
-
-
Drag the Neo4J connector onto the canvas and configure a new Global Element according to the table below:
Parameter Value Username
${neo4j.username}
Password
${neo4j.password}
BOLT URL
${neo4j.boltUrl}
REST URL
${neo4j.restUrl}
<neo4j:config name="Neo4j__Basic_Authentication" username="${neo4j.username}" password="${neo4j.password}" boltUrl="${neo4j.boltUrl}" restUrl="${neo4j.restUrl}" doc:name="Neo4j: Basic Authentication"/>
-
In the Properties Editor, configure:
Parameter Value Display Name
Create node (advanced)
Connector Configuration
Neo4j__Basic_Authentication
Operation
Execute
Query
#[flowVars.create]
Parameters Reference
#[payload]
Click Test Connection to confirm that Mule can connect with the Neo4J instance. If the connection is successful, click OK to save the configuration. Otherwise, review or correct any invalid parameters and test again.
-
-
Drag a Neo4J connector onto the canvas, in the Properties Editor, configure the parameters:
Parameter Value Display Name
Select node (Multi-label)
Operation
Execute
Query
#[flowVars.select]
-
Drag an Object to JSON onto the canvas.
-
Drag a Logger onto the canvas.
-
Save the changes and deploy the project as a Mule Application. Open a browser and make a request to the following URL:
http://localhost:8081/createNodeMultiLabel
If the node was successfully created and deleted, information should be displayed in a JSON format:
[{"a":{"born":1956,"name":"Tom Hanks"}}]
Connector Performance
To define the pooling profile for the connector manually, access the Pooling Profile tab in the global element for the connector.
For background information on pooling, see Tuning Performance.
See Also
-
For general documentation, see Neo4J Documentation.
-
Access the Neo4J Connector Release Notes.