Hi guys, I have question how to deal with application specific
configuration parameters...


I use elasticsearch to put/get specific documents and use them in a domain
model.

So I defined a domain service "EsClient" to access to elasticsearch - I use
service lifecycle to connect/disconnect to elasticseach.



According to ((https://isis.apache.org/reference/configuration-files.html)
) my first idea was to:

- put the configuration parameters into isis.properites
- get the parameter value in a domain service by
container.getProperty("propertyName");

Currently I get null value here...

Thanks,Vladimir



Here my code (relevant parts)

....
@Named("Elasticsearch")
@DomainService(menuOrder = "1.2")
public class EsClient {

 private static final String ES_CLUSTER_PROPERTY_NAME =
"elasticsearch.cluster";
 private static final String ES_SERVER_PROPERTY_NAME =
"elasticsearch.server";
 private static final String ES_SERVER_PORT_PROPERTY_NAME =
"elasticsearch.port";
..
...

  @SuppressWarnings("resource")
    @PostConstruct
    @Programmatic
    public void connectToEs() {

        final String esClusterName =
container.getProperty(ES_CLUSTER_PROPERTY_NAME);
        container.getUser()
        final String esServer =
container.getProperty(ES_SERVER_PROPERTY_NAME);
        final String esPort =
container.getProperty(ES_SERVER_PORT_PROPERTY_NAME);

        logger.info("Using elasticsearch properties from isis.poperties:" +
" server=" + esServer + "," + " port=" + esPort + "," + " cluster=" +
esClusterName);

        final Settings settings = ImmutableSettings.settingsBuilder().put("
cluster.name", esClusterName)
        // .put("node.name", ES_LOCAL_NODE_NAME)
                .put("client.transport.nodes_sampler_interval", "10") // 10
                                                                      //
seconds
                                                                      //
ping
                .put("client.transport.sniff", false).build();
        client = new TransportClient(settings).addTransportAddress(new
InetSocketTransportAddress(esServer, Integer.valueOf(esPort)));

        logger.info("Connected to elasticsearch:" + "  server=" + esServer
+ "," + " port=" + esPort + "," + " cluster=" + esClusterName);

        // instance a json mapper
        mapper = new ObjectMapper(); // create once, reuse

    }

    @PreDestroy
    @Programmatic
    public void disconnectFromES() {
        node.close();
    }
....

 // //////////////////////////////////////
    // Injected Services
    // //////////////////////////////////////

    @javax.inject.Inject
    private DomainObjectContainer container;

Reply via email to