Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-18-2018 10:53 AM
I have a graph representing the pub/sub messaging configuration details in our micro-service landscape.
For some use-cases, it makes more sense to have aggregated/collapse/rolled-up relationship between publishers and subscribers, hiding away various details.
The base graph model is as follows:
(publisher:Service )-[:PUBLISH]->(:Topic {name})<-[:TOPIC]-(:Subscription)-[:QUEUE]->(:Queue)<-[:OWNER]-(subscriber:Service)
In words:
Based on this graph model, I would like to create a new additional 'collapsed' or 'rolled-up' relationship called PUBSUP
The resulting graph model would look like this: (publisher:Service )-[:PUBSUB {topics}]->(subscriber:Service)
Being more accustomed to procedural languages like Java as opposed to query languages like Cypher, my first intuition is to program this - in Java - in a procedural style. And that will probably work.
However, I'm curious to learn how I could benefit from the expressiveness of Cypher to facilitate these requirements.
Any pointers to Cypher language elements that could help me out here are very much appreciated.
Kristel
11-19-2018 02:15 AM
That's as simple as
MATCH (publisher:Service )-[:PUBLISH]->(t:Topic)<-[:TOPIC]-(:Subscription)-[:QUEUE]->(:Queue)<-[:OWNER]-(subscriber:Service)
MERGE (publisher)-[ps:PUBSUB]->(subscriber)
ON CREATE SET ps.topics = [t.name]
ON MATCH SET ps.topics = ps.topics + t.name
The MERGE
avoids duplicated relationships between the same publisher and subscriber.
11-19-2018 03:28 AM
Thnx for the quick response Stefan.
This looks like a very elegant solution. I'm going to try it this afternoon.
All the sessions of the conference are now available online