Key strategies

The Kafka Connect Neo4j Connector is the recommended method to integrate Kafka with Neo4j, as Neo4j Streams is no longer under active development and will not be supported after version 4.4 of Neo4j.

The most recent version of the Kafka Connect Neo4j Connector can be found here.

With streams.source.topic.relationships.<TOPIC_NAME>.key_strategy=default, when I produce a message for relationships, only one of the associated node constraints will be returned, based on the following rule.

If there are multiple constraints, we sort by the number of the properties associated to the constraint, then by label name (alphabetically) and finally by properties name (alphabetically).

Finally, we take the properties of the first one.

So, if we have a start node with labels Person and Other, and we create 2 constraints like these:

CREATE CONSTRAINT ON (p:Other) ASSERT p.zxc IS UNIQUE;
CREATE CONSTRAINT ON (p:Person) ASSERT p.name IS UNIQUE;

the start.ids field produced, will be:

{"zxc": "FooBar"}

because properties size is the same (that is 1), but first label by name is Other.

Otherwise, with:

CREATE CONSTRAINT ON (p:Other) ASSERT p.zxc IS UNIQUE;
CREATE CONSTRAINT ON (p:Other) ASSERT p.name IS UNIQUE;

the start.ids field produced, will be:

{"name": "Sherlock"}

because of name property name compared to zxc.

Otherwise with streams.source.topic.relationships.<TOPIC_NAME>.key_strategy=all, any property participating in a unique constraint will be produced. So, with a start node with labels Person, Other, Another and with these constraints:

CREATE CONSTRAINT ON (p:Another) ASSERT p.zxc IS UNIQUE;
CREATE CONSTRAINT ON (p:Other) ASSERT p.name IS UNIQUE;
CREATE CONSTRAINT ON (p:Person) ASSERT p.surname IS UNIQUE;

the start.ids field produced, will be:

{ "name": "Sherlock", "surname": "Holmes", "zxc": "FooBar"}