package com.flowy.fomoapi

import akka.actor.ActorSystem
import akka.event.{Logging, LoggingAdapter}
import akka.stream.ActorMaterializer
import com.flowy.fomoapi.services.HttpService
import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.StrictLogging

import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success}

object Main extends App with StrictLogging {
  val config = ConfigFactory.parseString(s"akka.remote.netty.tcp.port = 2554").
    withFallback(ConfigFactory.parseString("akka.cluster.roles = [api]")).
    withFallback(ConfigFactory.load())

  implicit val actorSystem = ActorSystem("ClusterSystem", config)
  implicit val executor: ExecutionContext = actorSystem.dispatcher
  implicit val log: LoggingAdapter = Logging(actorSystem, getClass)
  implicit val materializer: ActorMaterializer = ActorMaterializer()

  val (startFuture, bl) = new HttpService().start()

  val host = bl.config.serverHost
  val port = bl.config.serverPort

  val system = bl.system

  startFuture.onComplete {
    case Success(b) =>
      logger.info(s"Server started on $host:$port")
      sys.addShutdownHook {
        b.unbind()
        bl.system.terminate()
        logger.info("Server stopped")
      }
    case Failure(e) =>
      logger.error(s"Cannot start server on $host:$port", e)
      sys.addShutdownHook {
        bl.system.terminate()
        logger.info("Server stopped")
      }
  }
}

package com.flowy.fomoapi

import akka.actor.ActorSystem
import akka.event.{Logging, LoggingAdapter}
import akka.stream.ActorMaterializer
import com.flowy.fomoapi.services.HttpService
import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.StrictLogging

import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success}

object Main extends App with StrictLogging {
  val config = ConfigFactory.parseString(s"akka.remote.netty.tcp.port = 2554").
    withFallback(ConfigFactory.parseString("akka.cluster.roles = [api]")).
    withFallback(ConfigFactory.load())

  implicit val actorSystem = ActorSystem("cluster-api", config)
  implicit val executor: ExecutionContext = actorSystem.dispatcher
  implicit val log: LoggingAdapter = Logging(actorSystem, getClass)
  implicit val materializer: ActorMaterializer = ActorMaterializer()

  val (startFuture, bl) = new HttpService().start()

  val host = bl.config.serverHost
  val port = bl.config.serverPort

  val system = bl.system

  startFuture.onComplete {
    case Success(b) =>
      logger.info(s"Server started on $host:$port")
      sys.addShutdownHook {
        b.unbind()
        bl.system.terminate()
        logger.info("Server stopped")
      }
    case Failure(e) =>
      logger.error(s"Cannot start server on $host:$port", e)
      sys.addShutdownHook {
        bl.system.terminate()
        logger.info("Server stopped")
      }
  }
}

Rename the actor system in the api to cluster-api so as not to conflict with other systems on the same machine when using clustering
Rename the actor system in the api to cluster-api so as not to conflict with other systems on the same machine when using clustering
