Skip to content

DatabaseException: This channel is not active and can't take messages #117

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

Open
jorge-indigo opened this issue Jun 15, 2018 · 1 comment

Comments

@jorge-indigo
Copy link

Hi!

I have a production ticket office which uses Vert.x for realtime and I connecto to MySQL but after a while, every query gets this exception: "com.github.mauricio.async.db.exceptions.DatabaseException: This channel is not active and can't take messages"

I have 4 Verticles and all look like this:

package com.redpass.ticket.verticles

import io.vertx.core.eventbus.EventBus
import io.vertx.ext.asyncsql.MySQLClient
import io.vertx.core.AbstractVerticle
import io.vertx.core.json.JsonObject
import io.vertx.core.json.JsonArray
import com.redpass.ticket.queries.EntertainmentQueries
import com.redpass.ticket.mappers.EntertainmentMapper
import io.vertx.core.json.JsonObject

class EntertainmentVerticle extends AbstractVerticle {

  @Override
  void start() {

    JsonObject config = config()
    Map mysqlConfig = config.getJsonObject("mysql").getMap()

    def client = MySQLClient.createNonShared vertx, new JsonObject(mysqlConfig)
    def mapper = new EntertainmentMapper()

    def connection = null

    client.getConnection { response ->
      if (response.succeeded())
        connection = response.result()
      else
        println "Cannot connect to MySQL"
    }

    EventBus eventBus = vertx.eventBus()

    eventBus.consumer("redpass.comunicate.entertainment") { message ->
      println "consuming redpass.comunicate.entertainment"

      def bodyMessage = message.body().getMap()
      def queryParams = new JsonArray().add(bodyMessage.eventId)

      connection.queryWithParams(EntertainmentQueries.FIND_BY_EVENT, queryParams, { response ->
        try {
          if (response.succeeded()) {
            def result = response.result()
            def rows = result.getRows()
            def entertainments = mapper.fromDatabase(rows)
            eventBus.send("redpass.comunicate.entertainment.response.${ bodyMessage.uuid }", mapper.fromEntity(entertainments))
          } else {
            throw response.cause()
          }
        } catch(Exception e) {
          eventBus.send("redpass.comunicate.entertainment.response.${ bodyMessage.uuid }", new JsonObject([ hasError: true, cause: e.toString() ]))
        }
      })
    }
  }
}

I thought it was the fact that I was using createShared on every verticle but I doesn't work even If I change it to createNonShared.

What's the problem with my code and how can i solve it?

@jorge-indigo
Copy link
Author

EntertainmentQueries.FIND_BY_EVENT is a plan SELECT query

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

No branches or pull requests

1 participant