package audit

import audit.Message.JsonWrites
import com.google.inject.Inject
import com.rabbitmq.client.ConnectionFactory
import play.api.Logger
import play.api.libs.json.Json.{stringify, toJson}
import utils.helpers.Config

final class AuditServiceImpl @Inject()(config: Config) extends AuditService {

  override def send(auditMessage: Message): Unit = {
    val factory = new ConnectionFactory()
    factory.setHost(config.rabbitmqHost)
    val connection = factory.newConnection() // TESTS NEED TO BE USING STUB SERVICE
    try {
      val channel = connection.createChannel()
      try {
        channel.queueDeclare(config.rabbitmqQueue, false, false, false, null)
        val message = messageToSend(auditMessage).getBytes
        channel.basicPublish("", config.rabbitmqQueue, null, message)
        Logger.debug(s"Sent Audit message: $message")
      } finally {
        channel.close()
      }
    } finally {
      connection.close()
    }
  }

  private def messageToSend(auditMessage: Message) = {
    val asJson = toJson(auditMessage)
    stringify(asJson)
  }
}
package audit

import audit.Message.JsonWrites
import com.google.inject.Inject
import com.rabbitmq.client.ConnectionFactory
import play.api.Logger
import play.api.libs.json.Json.{stringify, toJson}
import utils.helpers.Config

final class AuditServiceImpl @Inject()(config: Config) extends AuditService {

  override def send(auditMessage: Message): Unit = {
//    val factory = new ConnectionFactory()
//    factory.setHost(config.rabbitmqHost)
//    val connection = factory.newConnection() // TESTS NEED TO BE USING STUB SERVICE
//    try {
//      val channel = connection.createChannel()
//      try {
//        channel.queueDeclare(config.rabbitmqQueue, false, false, false, null)
//        val message = messageToSend(auditMessage).getBytes
//        channel.basicPublish("", config.rabbitmqQueue, null, message)
//        Logger.debug(s"Sent Audit message: $message")
//      } finally {
//        channel.close()
//      }
//    } finally {
//      connection.close()
//    }
    Logger.debug(s"Sent Audit message" + auditMessage)
  }

  private def messageToSend(auditMessage: Message) = {
    val asJson = toJson(auditMessage)
    stringify(asJson)
  }
}
Comment out code that equires rabbitmq to be installed and running
US1496: Comment out code that equires rabbitmq to be installed and running
