I have a Play 2.5.10 application with multiple data sources. I would like 
to start the application even if one of the data sources is not available.
HikariCP supports this, but Play does not seem to allow this as it will not
start unless it can get a successful connection to all data sources.
I see that someone filed a bug for this exact thing on Github
(https://github.com/playframework/playframework/issues/6706). The issue was
closed because the developers like this behavior, but some of the comments
seem to imply that it could work. Is that in fact true? I cannot seem to
find any way to configure the app in any way to allow it to start without a
connection.
*applicaiton.conf*
db {
api {
driver: org.mariadb.jdbc.Driver
url: "jdbc:mysql://01-mysql-pc.envnxs.net/api"
username: "mysql"
password: ""
initializationFailFast: false
hikaricp: {
initializationFailFast: false
}
}
report: {
driver: org.mariadb.jdbc.Driver
url: "jdbc:mysql://01-report-pc.envnxs.net/report"
username: "mysql"
password: ""
}
fast_report: {
driver: org.mariadb.jdbc.Driver
url: "jdbc:mysql://01-fast-report-pc.envnxs.net/report"
username: "mysql"
password: ""
}
destination {
driver: org.mariadb.jdbc.Driver
url: "jdbc:mysql://localhost/special"
username: ""
password: ""
}
}
*Output*
[info] application - Creating Pool for datasource 'destination'
[info] p.a.d.DefaultDBApi - Database [destination] connected at
jdbc:mysql://localhost:3306/special
[info] application - Creating Pool for datasource 'report'
[info] p.a.d.DefaultDBApi - Database [report] connected at
jdbc:mysql://01-report-pc.envnxs.net/report
[info] application - Creating Pool for datasource 'fast_report'
[info] p.a.d.DefaultDBApi - Database [fast_report] connected at
jdbc:mysql://01-fast-report-pc.envnxs.net/report
[info] application - Creating Pool for datasource 'api'
[info] application - Creating Pool for datasource 'destination'
[info] p.a.d.DefaultDBApi - Database [destination] connected at
jdbc:mysql://localhost:3306/special
[info] application - Creating Pool for datasource 'report'
[info] p.a.d.DefaultDBApi - Database [report] connected at
jdbc:mysql://01-report-pc.envnxs.net/report
[info] application - Creating Pool for datasource 'fast_report'
[info] p.a.d.DefaultDBApi - Database [fast_report] connected at
jdbc:mysql://01-fast-report-pc.envnxs.net/report
[info] application - Creating Pool for datasource 'api'
[info] application - Creating Pool for datasource 'destination'
[info] p.a.d.DefaultDBApi - Database [destination] connected at
jdbc:mysql://localhost:3306/special
[info] application - Creating Pool for datasource 'report'
[info] application - Creating Pool for datasource 'destination'
[info] p.a.d.DefaultDBApi - Database [destination] connected at
jdbc:mysql://localhost:3306/special
[info] application - Creating Pool for datasource 'report'
Oops, cannot start the server.
Configuration error: Configuration error[Cannot connect to database [api]]
at play.api.Configuration$.configError(Configuration.scala:154)
at play.api.Configuration.reportError(Configuration.scala:806)
at
play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:48)
at
play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42)
at scala.collection.immutable.List.foreach(List.scala:381)
at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42)
at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72)
at play.api.db.DBApiProvider.get(DBModule.scala:62)
at play.api.db.DBApiProvider.get(DBModule.scala:58)
at
com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
at
com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)
at
com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
at
com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)
at
com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:54)
at
com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132)
at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93)
at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80)
at
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
at
com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80)
at
com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:62)
at
com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:984)
at
com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
at
com.google.inject.util.Providers$GuicifiedProviderWithDependencies$$FastClassByGuice$$2a7177aa.invoke(<generated>)
at
com.google.inject.internal.cglib.reflect.$FastMethod.invoke(FastMethod.java:53)
at
com.google.inject.internal.SingleMethodInjector$1.invoke(SingleMethodInjector.java:57)
at
com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector.java:91)
at
com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132)
at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93)
at
com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80)
at
com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at
com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80)
at
com.google.inject.internal.Initializer$InjectableReference.get(Initializer.java:174)
at
com.google.inject.internal.Initializer.injectAll(Initializer.java:108)
at
com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:174)
at
com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:84)
at
play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:181)
at
play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
at
play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:47)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:22)
at play.core.server.ProdServerStart.main(ProdServerStart.scala)
Caused by: java.sql.SQLTransientConnectionException: HikariPool-4 -
Connection is not available, request timed out after 30003ms.
at
com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:548)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:186)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)
at
com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:83)
at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
at play.api.db.DefaultDatabase.getConnection(Databases.scala:138)
at
play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:44)
... 40 more
Caused by: java.sql.SQLNonTransientConnectionException: Could not connect
to address=(host-mysql-pc.envnxs.net)(port306)(type=master) :
01-mysql-pc.envnxs.net
at
org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
at
org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
at org.mariadb.jdbc.Driver.connect(Driver.java:107)
at
com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95)
at
com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:101)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:341)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:193)
at
com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:430)
at com.zaxxer.hikari.pool.HikariPool.access$500(HikariPool.java:64)
at
com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:570)
at
com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:563)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not
connect to address=(host-mysql-pc.envnxs.net)(port306)(type=master) :
01-mysql-pc.envnxs.net
at
org.mariadb.jdbc.internal.mysql.MySQLProtocol.connectWithoutProxy(MySQLProtocol.java:631)
at org.mariadb.jdbc.internal.common.Utils.retrieveProxy(Utils.java:541)
at org.mariadb.jdbc.Driver.connect(Driver.java:102)
... 12 more
Caused by: java.net.UnknownHostException: 01-mysql-pc.envnxs.net
at
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at
org.mariadb.jdbc.internal.mysql.MySQLProtocol.connect(MySQLProtocol.java:289)
at
org.mariadb.jdbc.internal.mysql.MySQLProtocol.connectWithoutProxy(MySQLProtocol.java:626)
... 14 more
I also tried setting play.db.prototype.hikaricp.initializationFailFastlse
but that didn't seem to help either.
Is this possible?
Nathan Levin-Greenhaw 's gravatar image asked Jan 11 2017 at 12:07 in Play-Framework by Nathan Levin-Greenhaw

4 Answers

Apparently, Play's DB module iterates through the connections defined in
the application.conf during start up and if it cannot get a connection to
any of them it throws an exception.
To work around this I created a new project that can be used to start a
Play application without needing a connection at start up time.
See https://github.com/njlg/playdb.
Nathan Levin-Greenhaw 's gravatar image answered Jan 18 2017 at 15:09 by Nathan Levin-Greenhaw
Hi Nathan,
Also check out Christopher Hunt's dynamic data source:
https://github.com/typesafehub/dynamic-data-source
Will Sargent
*Engineer, Lightbend,
Will Sargent 's gravatar image answered Jan 19 2017 at 14:31 by Will Sargent
Hi Nathan,
It looks like you've really thought this through. Would you consider
contributing this code to Play itself as a pull request?
Will Sargent
*Engineer, Lightbend,
Will Sargent 's gravatar image answered Jan 19 2017 at 14:33 by Will Sargent
Will,
Thanks for the response. Let me look into dynamic data source, because that
sounds similar.
I'd be happy to submit a PR for Play in next couple days.
Nathan
Nathan Levin-Greenhaw 's gravatar image answered Jan 30 2017 at 08:41 by Nathan Levin-Greenhaw

Related Discussions

  • [play-framework] Reactive Play in Play-framework

  • Hi all, I'm happy to announce the early access release of my book, Reactive Web Applications with Play . The book aims at being a guide for writing performant applications with Play, navigating around some of the pitfalls that come with the evented server model. It also gives an introduction to some of the fundamental aspects of functional programming that turn out to be quite useful when...

  • [play-framework] Play Certification in Play-framework

  • Hi all, We've had many requests from many users for certifications in Play Framework, so the Play team is proud to announce the introduction of a new certification program, the Certification Reactive Application Developer! For details, including instructions for becoming certified, see here: https://playframework.com/certification Regards, *James Roper* *Software Engineer* Typesafe...

  • [play-framework][play 2.4] in Play-framework

  • Hi all. Recently I'm facing a problem about Ebean and Postgresql raw query. I have sql syntax that using ::numeric (postgre syntax) and :worker_id to set parameter. When sql query was executed it produce error. The error said that :numeric has no value on parameter. So I realize that this syntax just conflict with Ebean prefix parameter maping or JPA prefix. Do you have solution about...

  • [play-framework] Play Exceptions in Play-framework

  • Hi, I am using play framework v1.2.4. I am getting "this exception has been logged with id..." messages from time to time in my application. Everytime I look at the application.log file, I don't see the error message logged. When I run the application locally, in prod mode, I do get to see the exception logged. Any idea what I can do to get the exceptions logged in my frontend ...

  • [play-framework] [2.4.0] Java.lang.NoClassDefFoundError: Play/Play$ in Play-framework

  • I just updated to latest play 2.4.0. I try using activator ui, but i receive the error as below. Anyone facing same issue here? - Done updating. - play/Play$ - java.lang.NoClassDefFoundError: play/Play$ - Use 'last' for the full log. - Failed to load project. You received this message because you are subscribed to the Google Groups "play-framework" group. To unsubscribe ...

  • Play Back in Jmeter-user

  • Hi, I am learing to use Jmeter. I am able to record all the transactions of my application(Java built), but I am unable to play them back. That is I cant see any screens as I do incase of winrunner. And I also noticed some pages which are not part of my application and I haven't visited during recording. Can any one help me out. Thanks in advance, Sunil...

  • Play Store. in Android-x86

  • Just installed 4.4-r2 and found Play Store in it. But including it requires a permission from Google. How did Android-X86 team obtain that permission? Thanks in advance for answer. You received this message because you are subscribed to the Google Groups "Android-x86" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]..

  • Group Play? in Eyes-free

  • Hey all! I recently ran into an app on my S4 Active running 4.2.2 that keeps nagging me to update it. It is called Group Play and seems to have come pre-installed with the device. Anyone knows what the heck this is? When I try to start it, it tells me that I *have* to install the newest update in order to run the app. When trying to update the app, it either crashes with a more or less ...

  • Play/Pause in Tasker

  • Hi Im trying to set up Tasker to control Play/Pause of music.when the power turns off to a tablet. I would like to pause playing music when the power is disconnected and then when the power turns on continue playing the music. the trouble im having is the music will start to play regardless on weather i was playing music in the first place. I tried using media utilities plugin and google...

  • Play-autosource in Scala-user

  • Pepole, whats your opinion about play-autosource? I am developing a play client and i need something like this but im not sure is that a good option. http://mandubian.com/2013/06/11/play-autosource/ Thanks...

  • Play Music in Eyes-free

  • So I heard the buttons were labelled and yes they are, but I can't seem to find an exit button. Does anyone know how to stop the player and then exit? You received this message because you are subscribed to the Google Groups "eyes-free" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] For more options...

  • Play Books in Eyes-free

  • Hi All, I want to send the developers of Play Books some feedback, but before I do, I want to be sure that these problems are the app, not the operator of my device. Please let me know if you observe the same behavior or know how to work with X or Y. some of these things aren't problems. I just want to make sure I understand the app. * On the Read now screen, books are arranged in a grid...

  • Play Framework in Spark-user

  • Hi - Has anybody figured out how to integrate a Play application with Spark and run it on a Spark cluster using spark-submit script? I have seen some blogs about creating a simple Play app and running it locally on a dev machine with sbt run command. However, those steps don't work for Spark-submit. If you have figured out how to build and run a Play app with Spark-submit, I would appreciate...

  • Play 2.1.5 in Play-framework

  • Hi everyone ...... I have started working on playframwork version 2.1.5 with the Java I need some help any exemple any tutoriel...

  • Play Framework in Play-framework

  • reference to Post is ambiguous; it is imported twice in the same scope by import controllers._ and import models._...

  • Play Features in Play-framework

  • Hey Guys, Someone use play! to work which Corporate Applications? Have some big company that use play! in yours applications?...

  • Play Day in Play-framework

  • I thought some people here might be interested in Play Day, an online event which is happening next week: Join us for Play Day, our first ever virtual conference on Tuesday, June 3rd, 2014. Were hosting a full day of webinars all about the Play Framework! Speakers from the Typesafe Play team, Huffington Post, Angies List, Gilt and more will share their experiences with Play. Sessions range from...

  • Play Vulnerabilities? in Play-framework

  • Hi, Out of curiosity, does an empty play-framework-security list (https://groups.google.com/forum/#!forum/play-framework-security) indicate that there has not been a single vulnerability in play? Also, do you relay security advisories from dependent libraries is that up to the users of the framework to check? Cheers, Mathias...

  • Play Roadmap in Play-framework

  • Hey there community, Just to let you know that we've published some thoughts on our roadmap given ScalaDays and our engineering meet up. We'd love to get your feedback. https://docs.google.com/document/d/11sVi1-REAIDFVHvwBrfRt1uXkBzROHQYgmcZNGJtDnA/edit?usp=sharing Kind regards, Christopher -- Christopher Hunt Bit twiddler @ Typesafe def reactive(): Unit = {val (eventDriven, scalable, resilient...

  • Embedding Play in Play-framework

  • Hello, Are there any examples of embedding play available? Basically I would like to programmatically start/stop Play powered HTTP endpoints within an existing application. Thanks, Andrew...