SpinGo / op-rabbit

The Opinionated RabbitMQ Library for Scala and Akka
Other
232 stars 73 forks source link

read from one RabbitMQ and publish to another #170

Open accu-knauthg opened 5 years ago

accu-knauthg commented 5 years ago

I have to read from a RabbitMQ in Canada and publish to an internal RabbitMQ here in the US. I have all the credentials, I'm just trying to figure out what the code would look like, since typical application.conf setups only have one RabbitMQ. I have to connect to / read from the one in Canada using SSL.

urcadox commented 5 years ago

Hello,

You can do this:

val firstRabbit = actorSystem.actorOf(Props(
  new RabbitControl(ConnectionParams.fromConfig(
    conf.getConfig("op-rabbit.first")
  )
))
val secondRabbit = actorSystem.actorOf(Props(
  new RabbitControl(ConnectionParams.fromConfig(
    conf.getConfig("op-rabbit.second")
  )
))

The config looks like this:

op-rabbit {
  topic-exchange-name = ${RABBITMQ_EXCHANGE}
  first {
    hosts = [${RABBITMQ_FIRST_HOST}]
    username = ${RABBITMQ_FIRST_USER}
    password = ${RABBITMQ_FIRST_PASSWORD}
    connection-timeout = 3s
    virtual-host = "/"
    port = ${RABBITMQ_FIRST_PORT}
    ssl = true
  }

  second {
    hosts = [${RABBITMQ_SECOND_HOST}]
    username = ${RABBITMQ_SECOND_USER}
    password = ${RABBITMQ_SECOND_PASSWORD}
    connection-timeout = 3s
    virtual-host = "/"
    port = ${RABBITMQ_SECOND_PORT}
    ssl = true
  }
}
accu-knauthg commented 5 years ago

@urcadox : Thank you, I'll try that!