Skip to content
This repository was archived by the owner on Jun 11, 2021. It is now read-only.

Publisher disconnects from queue when AskTimeoutException encountered #79

@rohitmukherjee

Description

@rohitmukherjee

Hi Fabrice,

Firstly, thanks for building such a useful library. We use it in a service that publishes email requests onto a queue. Normally, we don't face any issues but sometimes we face the following exception:

akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://actor-ystem/user/$3j/$a#-1930803633]] after [5000 ms]

After we encounter this exception a service restart is required to reconnect to the queue. We'd like if we could just reconnect without having to restart the service.

A simplified example is shown below:


val publisher = createPublisher()

def sendEmail(emailRequest: EmailRequest)(implicit ec: ExecutionContext): Future[Amqp.Publish] = {
     val props = // Build props from EmailRequest
     val queue = getQueue()
     def publish(_publisher: ActorRef) = _publisher ? Publish("", queue, Array[Byte](), Option(props))
     val future = publish(publisher) map {
        case Ok(request, _) => request
        case Error(request, errorVal) => logging
        case s => throw new RuntimeException(s"$s")
     }
}

def createPublisher()(implicit ec: ExecutionContext) = {
        val publisher = ConnectionOwner.createChildActor(conn, ChannelOwner.props())
        Amqp.waitForConnection(system, publisher).await()
        info(s"Publisher connected on server $rabbitUri")
        DeclareQueue(QueueParameters("myQueue", passive = false, durable = true, exclusive = false, autodelete = false, args = queueArgs))
        // must wait for results so we don't send to queues before they're declared
        Await.result(delayQueueFutures, Timeout(5 seconds).duration)
        publisher
    }

The sendMail function is what encounters the disconnect, how would you recommend recovering and reconnecting? I considered recreating the publisher but am not sure of whether that's a good idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions