Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration of multiple datasources (same DB type) #35

Open
wisteso opened this issue Apr 8, 2021 · 2 comments
Open

Configuration of multiple datasources (same DB type) #35

wisteso opened this issue Apr 8, 2021 · 2 comments

Comments

@wisteso
Copy link

wisteso commented Apr 8, 2021

I've read the documentation which talks about using environment variables to set the DB user/pass/schema/etc. However, multiple datasources will not work this way unless there's something I'm missing?

Not using OpenShift - Looking for something that will work on bare metal or cloud.

@wisteso wisteso changed the title How to configure multiple datasources? Configuration of multiple datasources (same DB type) Apr 8, 2021
@jfdenise
Copy link
Contributor

@wisteso , yes, for multiple datasources you will need to use WildFly CLI scripts. If you are using Bootable JAR, then CLI scipt execution is integrated in the Maven plugin that produces WildFly Bootable JAR.

@d-schmidt
Copy link

The solution looks like this:

<plugin>
  <groupId>org.wildfly.plugins</groupId>
  <artifactId>wildfly-jar-maven-plugin</artifactId>
  <version>${wildfly.bootable.jar.plugin.version}</version>
  <configuration>
    <dump-original-artifacts>true</dump-original-artifacts>
    <log-time>true</log-time>
    <contextRoot>false</contextRoot> <!-- disable root deployment -->
    <feature-packs>
      <feature-pack>
        <location>wildfly@maven(org.jboss.universe:community-universe)#${wildfly.version}</location>
      </feature-pack>
      <feature-pack>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-datasources-galleon-pack</artifactId>
        <version>${wildfly.ds.galleon.version}</version>
      </feature-pack>
    </feature-packs>
    <layers>
      <layer>jaxrs-server</layer>
      <layer>mail</layer>
      <layer>postgresql-driver</layer>
      <layer>ejb-lite</layer>
    </layers>
    <excluded-layers>
      <layer>deployment-scanner</layer>
    </excluded-layers>
    <cli-sessions>
      <cli-session>
        <script-files>
          <script>../wildfly-jar-scripts/server-cfg.cli</script>
        </script-files>
        <properties-file>wildfly.properties</properties-file>
      </cli-session>
      <cli-session>
        <script-files>
          <script>../wildfly-jar-scripts/db.cli</script>
        </script-files>
        <!-- We want the env variables to be resolved during server execution -->
        <resolve-expressions>false</resolve-expressions>
      </cli-session>
    </cli-sessions>
    <extra-server-content-dirs>
      <extra-content>../manual/wildfly-jar-extra-content</extra-content>
    </extra-server-content-dirs>
    <plugin-options>
      <jboss-fork-embedded>false</jboss-fork-embedded>
    </plugin-options>
    <cloud>
      <type>kubernetes</type>
    </cloud>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>package</goal>
      </goals>
    </execution>
  </executions>
</plugin>

and db.cli with multiple lines like:

data-source add --name=read_write --jndi-name=java:jboss/datasource/ReadWriteDS --jta=true --driver-name=postgresql --user-name=${env.POSTGRESQL_USER} --password=${env.POSTGRESQL_PASSWORD} --connection-url=jdbc:postgresql://${env.POSTGRESQL_HOST}:${env.POSTGRESQL_PORT}/${env.POSTGRESQL_DB} --exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter --validate-on-match=false --background-validation=true --background-validation-millis=10000 --check-valid-connection-sql="SELECT 1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants