Skip to content
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

What would be the best way? #44

Open
juanstiza opened this issue Aug 7, 2017 · 0 comments
Open

What would be the best way? #44

juanstiza opened this issue Aug 7, 2017 · 0 comments

Comments

@juanstiza
Copy link
Contributor

juanstiza commented Aug 7, 2017

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!!

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

No branches or pull requests

1 participant