0

What's the right way to pass some configuration parameters to a module that I wrote for neo4j + GraphAware? I believe there should be a way that I can put some config entries in neo4j.conf and read them in my module's code but so far I could not find it.

Mehran
  • 15,593
  • 27
  • 122
  • 221

1 Answers1

2

There is definitely a possibility to pass configuration parameters to your module.

The best way is to look at other modules that use such configuration, GraphAware not being shy to open source modules (https://github.com/graphaware?utf8=%E2%9C%93&q=&type=&language=java) you can find plenty of it.

Let's take the uuid-module as an example :

In the bootstrapper class, you will find the logic for reading configuration parameters from the config file :

String uuidProperty = config.get(UUID_PROPERTY);
        if (StringUtils.isNotBlank(uuidProperty)) {
            configuration = configuration.withUuidProperty(uuidProperty);
            LOG.info("uuidProperty set to %s", configuration.getUuidProperty());
        }

https://github.com/graphaware/neo4j-uuid/blob/master/src/main/java/com/graphaware/module/uuid/UuidBootstrapper.java#L55

The found parameters are used to create an immutable Configuration class :

https://github.com/graphaware/neo4j-uuid/blob/master/src/main/java/com/graphaware/module/uuid/UuidConfiguration.java

The end of the module bootstrapping will then pass the configuration object to the constructor of the module :

return new UuidModule(moduleId, configuration, database);

https://github.com/graphaware/neo4j-uuid/blob/master/src/main/java/com/graphaware/module/uuid/UuidBootstrapper.java#L89

You can then use this module with the configuration :

public UuidModule(String moduleId, UuidConfiguration configuration, GraphDatabaseService database) {
        super(moduleId);        
        this.uuidConfiguration = configuration;
        this.uuidGenerator = instantiateUuidGenerator(configuration, database);
        this.uuidIndexer = new LegacyIndexer(database, configuration);
    }

https://github.com/graphaware/neo4j-uuid/blob/master/src/main/java/com/graphaware/module/uuid/UuidModule.java

Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36