Reputation: 691
I'm looking for the best way to configure Slick 3 with a typical master/slave mysql schema. Basically I want to send writes to a mysql server and reads to another one and trust the two servers are synchronized.
I've readed [this][1] but I think is for Slick 2. I've readed the Slick official doc and I don't see anything about this topic.
Now, with one database (no master slave) i have this in application.conf.
slick {
dbs {
default {
driver = "slick.driver.MySQLDriver$"
db {
driver = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost/new_chat"
user = "new_chat"
password = "new_chat"
}
}
}
}
and I'm executing queries like this:
PersistenceUtils.run(conversationMembers += conversationMember)
PersistenceUtils:
def run[R](a: DBIOAction[R, NoStream, Nothing])
(implicit chatContext: ChatContext, ec: ExecutionContext): Future[R] = {
val result = chatContext.db.run(a)
result.onFailure({ case e => logger.error(s"error executing query: ${a.getDumpInfo.mainInfo}", e) })
result
}
There is a way to do this with configuration in application.conf? I do not want master/slave in dev, only in staging and production. I've read about a ReplicationDriver but I don't see anything in Slick doc :S
Anybody can give me some clue? :P
Thank you
Upvotes: 2
Views: 785
Reputation: 2764
Configure your jdbc url like below:
jdbc:mysql:replication://master,slave1,slave2,slave3/<database>
And set the driver to:
com.mysql.jdbc.ReplicationDriver
Once you are done with the above, all that you have to do is to mark the queries, that need to go to slave machines, as readonly. So, all jdbc connections that are readonly are delegated to slave machines and the ones that are not readonly are sent to the master.
Upvotes: 7