rebus-org / Rebus.MySql

:bus: MySQL integration for Rebus
https://mookid.dk/category/rebus
Other
7 stars 6 forks source link

Avoid MySQL access during startup if not creating tables #22

Closed kendallb closed 2 years ago

kendallb commented 2 years ago

If MySQL is down when Rebus is initialized, if we are not requesting that the tables be created some stuff still ends up a) trying to create tables (from PoisonQueueErrorHandler) and also when initializing the MySqlSubscriptionStorage it reads column schema data. So changed the code so that the table is not created if not requested when the poison error queue is created, and we defer to reading of the column widths from the subscription table until we actually need it. 99% of the time and 100% if the table was automatically created, the column widths will match the defaults.

With these changes if MySQL is down and Rebus is initialized in a process that is not reading messages (ie: code that just posts to it as a one way queue), we can avoid hitting the MySQL database so if it is down, we still come up just fine and can then resume operations when its up.

Clearly if MySQL is down and the code needs to read and process messages, or if automatic table creation is always enabled (we only enable this for our message processing queue code which is out of process to our web server code), it needs to fail. So this way if MySQL is down our web sites will still start just fine in a 'down for maintenance' state, while the actual message processing services will fail to start. We start those manually when MySQL is back up. Those will crash pretty quickly when MySQL is down, but the web site code is designed to gracefully produce a down for maintenance page if the database crashed out.


Rebus is MIT-licensed. The code submitted in this pull request needs to carry the MIT license too. By leaving this text in, I hereby acknowledge that the code submitted in the pull request has the MIT license and can be merged with the Rebus codebase.

mookid8000 commented 2 years ago

Cool 👍 it's out on NuGet.org now as Rebus.MySql 3.0.0-b8

kendallb commented 2 years ago

Excellent, thanks!