Skip to content

What would be the best way? #44

@juanstiza

Description

@juanstiza

Im trying to:

  1. Create channel,
  2. Bind things,
  3. Publish a list of messages,
  4. Close everything and wait for it to close,
  5. Shut down system.

Here is my code:

import akka.actor.{ActorRef, ActorSystem}
import com.newmotion.akka.rabbitmq._

import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext}

val queueName = "my-queue"
val exchange = "my-queue"
val cf: ConnectionFactory = new ConnectionFactory()

val sys = ActorSystem("queue-system")
implicit val ec: ExecutionContext = sys.dispatcher
val conn = sys.actorOf(ConnectionActor.props(cf), "connection")

def setupProducer(channel: Channel, self: ActorRef) {
  val queue = channel.queueDeclare(queueName, true, false, false, java.util.Collections.emptyMap[String, AnyRef]()).getQueue
  channel.exchangeDeclare(exchange, "direct", true)
  channel.queueBind(queue, exchange, "")
}

val channel = conn.createChannel(ChannelActor.props(setupProducer), Some("publisher"))

val events = List("1", "2", "3")
events.map(_.getBytes) map { data =>
  channel ! ChannelMessage((c: Channel) => {
    c.basicPublish("",queueName, null, data)
  })
}

sys stop channel
sys stop conn
Await.result((for {
  c <- sys.whenTerminated
} yield c), 30 seconds)

I'm getting these errors:

[INFO] [08/07/2017 14:51:56.472] [queue-system-akka.actor.default-dispatcher-4] [akka://queue-system/user/connection/publisher] Message [com.newmotion.akka.rabbitmq.ChannelMessage] from Actor[akka://queue-system/deadLetters] to Actor[akka://queue-system/user/connection/publisher#1004003557] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[INFO] [08/07/2017 14:51:56.472] [queue-system-akka.actor.default-dispatcher-4] [akka://queue-system/user/connection/publisher] Message [com.newmotion.akka.rabbitmq.AmqpShutdownSignal] from Actor[akka://queue-system/user/connection/publisher#1004003557] to Actor[akka://queue-system/user/connection/publisher#1004003557] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[INFO] [08/07/2017 14:51:56.474] [queue-system-akka.actor.default-dispatcher-3] [akka://queue-system/user/connection] closing connection to amqp://user@localhost:5672//
[INFO] [08/07/2017 14:51:56.479] [queue-system-akka.actor.default-dispatcher-2] [akka://queue-system/user/connection] Message [com.newmotion.akka.rabbitmq.AmqpShutdownSignal] from Actor[akka://queue-system/user/connection#-1778410342] to Actor[akka://queue-system/user/connection#-1778410342] was not delivered. [3] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

What is the best way to accomplish this? I guess when I want to shut down, the connection hasn't event published the messages, is there a way of waiting for it?

Thanks!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions