Nav

Neo4j Connector

Select

Anypoint Connector for Neo4j provides the capability to execute CQL statements and run basic operations, such as create, update, delete, and select nodes against a Neo4j Graph database instance.

Prerequisites

This document assumes that you are familiar with Neo4j, Mule, Anypoint Connectors, Anypoint Studio, Mule concepts, elements in a Mule flow, and Global Elements.

You need login credentials to test your connection to your target resource.

For hardware and software requirements and compatibility information, see the Connector Release Notes listed in the See Also section of this document.

To use this connector with Maven, view the pom.xml dependency information in the Dependency Snippets in Anypoint Exchange.

What’s New in this Connector

Support for Mule 4 has been added.

Metadata

Neo4j connector metadata is based on the following premises:

  • Labels listed on operations are the labels that are instanced in the database.

  • The database has these constraints for its nodes:

    • Unique property constraints.

    • Property existence constraints.

    • At least one node with constraint values defined in the database.

To Connect in Design Center

  1. Click a trigger such as an HTTP Listener or Scheduler trigger.

    Trigger options

  2. To create an HTTP global element for the connector, set these fields:

    Http Listener configuration

    Field Description

    Protocol

    Protocol selected for the HTTP endpoint, it can be HTTP or HTTPS (secure).

    Host

    IP address where your Mule application listens for requests.

    Port

    Port address where your Mule application listens for requests.

    Base Path

    Path where your Mule application listens for requests.

  3. Select the plus sign to add a component.

    add connector

  4. Select the connector as a component.

  5. Select the operation.

    operations connector

    Name Description

    Execute

    Execute any CQL statement against the database.

    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 more nodes based on a specific label. This lets you delete nodes with inbound or outbound relationships. Optional Properties can be added as search filter criteria.

    Note: The Neo4j connector’s basic operations can filter nodes by only one label in its query. If you want to filter in a query by multiple labels, use the Execute operation with a proper CQL statement.

  6. Configure the Global element for the connector.

    config connector

    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).

Connect in Anypoint Studio 7

You can use this connector in Anypoint Studio by adding it as a dependency in your Mule application.

Install Connector in Studio

  1. In Anypoint Studio, click the Exchange icon in the Studio task bar.

  2. Click Login in Anypoint Exchange.

  3. Search for the connector and click Install.

  4. Follow the prompts to install the connector.

After you install the connector, check that your pom.xml file is set correctly:

  1. Open your Mule project in Anypoint Studio.

  2. Add the connector as a dependency in the pom.xml file:

    
                 
              
    1
    2
    3
    4
    5
    6
    
    <dependency>
      <groupId>org.mule.connectors</groupId>
      <artifactId>mule-neo4j-connector</artifactId>
      <version>3.0.0</version>
      <classifier>mule-plugin</classifier>
    </dependency>

Configure in Studio

  1. Drag and drop the connector to the Studio Canvas.

  2. Select the operation.

    operations connector

    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.

    Note: The Neo4j connector’s basic operations can filter nodes by only one label in its query. If you want to filter in a query by multiple labels, use the Execute operation with a proper CQL statement.

  3. Configure the Global element for the connector.

    config connector

    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).

Use Case: Node Basic CRUD

Example Flow

  1. Create a new Mule Project in Anypoint Studio and set your Neo4j environment properties in src/main/resources/automation-credentials.properties.

    
                
             
    1
    2
    3
    4
    
    config.username=<USERNAME>
    config.password=<PASSWORD>
    config.boltUrl=<BOLT_URL_ENDOPOINT>
    config.restUrl=<REST_URL_ENDPOINT>
  2. Drag an HTTP connector onto the canvas and configure it with the default values.

  3. 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 2.0
    %output application/json
    ---
    {
            "name":"Tom Hanks",
            "born": 1956
    }
  4. 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}

    
                
             
    1
    2
    3
    4
    5
    6
    7
    
    <neo4j:config name="Neo4j_Config" doc:name="Neo4j Config">
            <neo4j:connection username="${config.username}"
            password="${config.password}"
            boltUrl="${config.boltUrl}"
            restUrl="${config.restUrl}" />
            </neo4j:config>
    </neo4j:config>
  5. In the Properties Editor, configure:

    Parameter Value

    Display Name

    Create node

    Connector Configuration

    Neo4j__Basic_Authentication

    Operation

    Create node

    Label

    Person

    Parameters Reference

    #[payload]

    Create node

    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.

  6. Drag a Neo4j connector onto the canvas, in the Properties Editor, configure the parameters:

    Parameter Value

    Operation

    Select nodes

    Label

    Person

  7. Drag a Neo4j connector onto the canvas, in the Properties Editor, configure the parameters:

    Parameter Value

    Operation

    Delete nodes

    Label

    Person

  8. Drag an Transform Message onto the canvas.

    
                
             
    1
    2
    3
    4
    
    %dw 2.0
    %output application/json
    ---
    payload
  9. 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 displays in a JSON format:

    {"born":1956,"name":"Tom Hanks"}

Create a node with multiple labels

Example Flow

  1. Create a new Mule Project in Anypoint Studio and set your Neo4j environment properties in src/main/resources/automation-credentials.properties.

    
                 
              
    1
    2
    3
    4
    
    config.username=<USERNAME>
    config.password=<PASSWORD>
    config.boltUrl=<BOLT_URL_ENDOPOINT>
    config.restUrl=<REST_URL_ENDPOINT>
  2. Drag an HTTP connector onto the canvas and configure it with the default values.

  3. Drag a Transform Message onto the canvas and create two flowVars with the following code:

    1. Variable-create

      
                      
                   
      1
      2
      3
      4
      
      %dw 2.0
      %output application/json
      ---
      "CREATE (a:ACTOR:PERSON { name:\"Tom Hanks\", born:1956 })"
    2. Variable-select

      
                      
                   
      1
      2
      3
      4
      
      %dw 2.0
      %output application/json
      ---
      "MATCH (a:ACTOR:PERSON) RETURN a"
  4. 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}

    
                 
              
    1
    2
    3
    4
    5
    6
    7
    
    <neo4j:config name="Neo4j_Config" doc:name="Neo4j Config">
            <neo4j:connection username="${config.username}"
            password="${config.password}"
            boltUrl="${config.boltUrl}"
            restUrl="${config.restUrl}" />
            </neo4j:config>
    </neo4j:config>
  5. In the Properties Editor, configure:

    Parameter Value

    Display Name

    Create node (advanced)

    Connector Configuration

    Neo4j__Basic_Authentication

    Operation

    Execute

    Query

    #[vars.create]

    Parameters Reference

    #[payload]

    Create node

    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.

  6. 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

    #[vars.select]

  7. Drag a Transform Message onto the canvas.

  8. Drag a Logger onto the canvas.

  9. 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 displays in a JSON format:

    [{"a":{"born":1956,"name":"Tom Hanks"}}]

Use Case: XML


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:neo4j="http://www.mulesoft.org/schema/mule/neo4j"
        xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
        xmlns:http="http://www.mulesoft.org/schema/mule/http"
        xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        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/http
        http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
        http://www.mulesoft.org/schema/mule/ee/core
        http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
        http://www.mulesoft.org/schema/mule/neo4j
        http://www.mulesoft.org/schema/mule/neo4j/current/mule-neo4j.xsd">
        <http:listener-config name="HTTP_Listener_config"
        doc:name="HTTP Listener config" basePath="/" >
                <http:listener-connection host="0.0.0.0" port="8081" />
        </http:listener-config>
        <neo4j:config name="Neo4j_Config" doc:name="Neo4j Config">
                <neo4j:connection username="${config.username}"
                 password="${config.password}" boltUrl="${config.boltUrl}"
                 restUrl="${config.restUrl}" />
        </neo4j:config>
        <flow name="CRUD" >
                <http:listener doc:name="Listener"
                 config-ref="HTTP_Listener_config" path="/CRUD"/>
                <ee:transform doc:name="Transform Message" >
                        <ee:message >
                                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
        "name":"Tom Hanks",
        "born": "1956"
}]]></ee:set-payload>
                        </ee:message>
                </ee:transform>
                <neo4j:create-node label="Person" doc:name="Create node"
                 config-ref="Neo4j_Config" input="#[payload]"/>
                <neo4j:select-nodes label="Person" doc:name="Select nodes"
                 config-ref="Neo4j_Config" input="#[payload]"/>
                <neo4j:delete-nodes label="Person" doc:name="Delete nodes"
                 config-ref="Neo4j_Config" parameters="#[payload]"/>
                <ee:transform doc:name="Transform Message">
                        <ee:message >
                                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
                        </ee:message>
                </ee:transform>
        </flow>
        <flow name="createNodeWithMultiLabels">
                <http:listener doc:name="Listener"
                config-ref="HTTP_Listener_config"
                path="/createNodeMultiLabel"/>
                <ee:transform doc:name="Transform Message">
                        <ee:message >
                                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{

}]]></ee:set-payload>
                        </ee:message>
                        <ee:variables >
                                <ee:set-variable variableName="select" ><![CDATA[%dw 2.0
output application/json
---
"MATCH (a:ACTOR:PERSON) RETURN a"]]></ee:set-variable>
                                <ee:set-variable variableName="create" ><![CDATA[%dw 2.0
output application/json
---
"CREATE (a:ACTOR:PERSON { name:\"Tom Hanks\", born:1956 })"]]></ee:set-variable>
                        </ee:variables>
                </ee:transform>
                <neo4j:execute doc:name="Create node (advanced)" config-ref="Neo4j_Config" input="#[payload]">
                        <neo4j:query ><![CDATA[#[vars.create]]]></neo4j:query>
                </neo4j:execute>
                <neo4j:execute doc:name="Select node (Multi-label)"  config-ref="Neo4j_Config">
                        <neo4j:query ><![CDATA[#[vars.select]]]></neo4j:query>
                </neo4j:execute>
                <ee:transform doc:name="Transform Message">
                        <ee:message >
                                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
                        </ee:message>
                </ee:transform>
        </flow>
</mule>