# Configuration

{% hint style="warning" %}
**This is the manual for older MicroStream versions (Version < 5.0).**

**The new documentation (Version >= 5.0) is located at:**

[https://docs.microstream.one/](https://docs.microstream.one/manual)
{% endhint %}

The `EmbeddedStorageManager` is mostly created with factory methods of `EmbeddedStorage`, where the most common settings, like database directory or the root instance, can be configured.

```java
EmbeddedStorageManager storageManager = EmbeddedStorage.start(
    myRoot,                 // root object of entity graph
    Paths.get("data-dir")    // storage data directory
);
```

## Foundations

To achieve a more detailed customization, you can utilize the `EmbeddedStorageFoundation` factory type. It holds and creates on demand all the parts that form an `EmbeddedStorageManager`.

```java
EmbeddedStorageManager storageManager = EmbeddedStorageFoundation.New()
    .setConfiguration(
        StorageConfiguration.Builder()
            .setChannelCountProvider(StorageChannelCountProvider.New(4))
            .setBackupSetup(StorageBackupSetup.New(Paths.get("backupdir")))
            .createConfiguration()
    )
    .createEmbeddedStorageManager();
```

## External Configuration

The artifact `storage.embedded.configuration` provides a convenience layer for configuration purposes, as well as facilities to read external configuration.&#x20;

{% code title="pom.xml" %}

```markup
<repositories>
    <repository>
        <id>microstream-releases</id>
        <url>https://repo.microstream.one/repository/maven-public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>one.microstream</groupId>
        <artifactId>storage.embedded.configuration</artifactId>
        <version>03.00.00-MS-GA</version>
    </dependency>
</dependencies>
```

{% endcode %}

The `Configuration` type consolidates the most widely used parameters from the storage foundations in one place. It's output is an `EmbeddedStorageFoundation` from which a `EmbeddedStorageManager` can be created.

```java
EmbeddedStorageManager storageManager = Configuration.Default()
    .setBaseDirectoryInUserHome("data-dir")
    .setBackupDirectory("backup-dir")
    .setChannelCount(4)
    .createEmbeddedStorageFoundation()
    .createEmbeddedStorageManager();
```

To read an external configuration use `ConfigurationLoader` and `ConfigurationParser` or the `Load*()` methods of `Configuration`. Currently XML and INI files are supported.

{% tabs %}
{% tab title="java (xml)" %}

```java
Configuration configuration = Configuration.LoadXml(
    HelloWorld.class.getResource("/META-INF/microstream/storage.xml")
);
```

{% endtab %}

{% tab title="xml" %}

```markup
<?xml version="1.0" encoding="UTF-8"?>
<properties>
    <property name="baseDirectory" value ="data" />
    <property name="channelCount" value ="4" />
</properties>
```

{% endtab %}

{% tab title="java (ini)" %}

```java
Configuration configuration = Configuration.LoadIni(
    HelloWorld.class.getResource("/META-INF/microstream/storage.ini")
);
```

{% endtab %}

{% tab title="ini" %}

```
baseDirectory = data
channelCount = 4
```

{% endtab %}
{% endtabs %}

If you just use `Configuration.Load()` the default configuration file is used, which is either a file in the classpath root named `microstream-storage.properties`, or the path configured via the system property `microstream.storage.configuration.path`.

{% hint style="info" %}
The full example can be found on [GitHub](https://github.com/microstream-one/examples/tree/3.0/helloworld-ini).
{% endhint %}

{% hint style="info" %}
If you use a different format, e.g. Json, just implement the `ConfigurationParser` in the likes of `XmlConfigurationParser` or `IniConfigurationParser`.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://manual.docs.microstream.one/3.0/data-store/configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
