Both http servers (jetty and akka-http) will try to bind to the specified port (9001) and the OS will only allow the first one to succeed, leading to the exception you are seeing in the process that is second to start.

If you must have them serve requests on the same port, then the way I see is to have each use a different port and put a proxy on 9001 that forwards to either of them based on the path.

But if you can, just use different ports :-)

Cheers,
Michal

On 13/04/17 10:11, Seongjong Jeon wrote:
Hey folks,

I've used AKKA Camel for HTTP service...

It's endpoint is "jetty:http://0.0.0.0:9001/test";

and recently I figured out that AKKA-HTTP is easy and fun.

So I tried bind akka-http route("http://0.0.0.0:9001/hi on same port.

val route =
   path("hi") {
     get {
         complete("hello")

     }
}
Http().bindAndHandle(route, "0.0.0.0", 9001)


I thought that both work properly 'cause two endpoints are different

                          AKKA Camel : http://0.0.0.0:9001/test

                          AKKA HTTP: http://0.0.0.0:9001/hi

But it didn't work with bindException.

WARN 2017-04-13 17:29:39 [catalogrefinement-akka.actor.default-dispatcher-18]o.e.j.u.component.AbstractLifeCycle : FAILED ServerConnector@74a1b9a6{HTTP/1.1}{0.0.0.0:9001}: java.net.BindException: Address already in use
java.net.BindException: Address already in use
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:321)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.server.Server.doStart(Server.java:366)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.apache.camel.component.jetty.JettyHttpComponent.connect(JettyHttpComponent.java:341) at org.apache.camel.http.common.HttpCommonEndpoint.connect(HttpCommonEndpoint.java:143)
at org.apache.camel.http.common.HttpConsumer.doStart(HttpConsumer.java:54)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:3371) at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:3688) at org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:3624) at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3544) at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3567) at org.apache.camel.impl.DefaultCamelContext.startRouteService(DefaultCamelContext.java:3421) at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1010) at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3397) at org.apache.camel.impl.DefaultCamelContext.addRouteDefinitions(DefaultCamelContext.java:942) at org.apache.camel.builder.RouteBuilder.populateRoutes(RouteBuilder.java:418) at org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:331) at org.apache.camel.impl.DefaultCamelContext$1.call(DefaultCamelContext.java:869) at org.apache.camel.impl.DefaultCamelContext$1.call(DefaultCamelContext.java:866) at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2976) at org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:866) at akka.camel.internal.ConsumerRegistrar$$anonfun$receive$4.applyOrElse(CamelSupervisor.scala:200)
at akka.actor.Actor$class.aroundReceive(Actor.scala:497)
at akka.camel.internal.ConsumerRegistrar.aroundReceive(CamelSupervisor.scala:195)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
at akka.actor.ActorCell.invoke_aroundBody0(ActorCell.scala:495)
at akka.actor.ActorCell$AjcClosure1.run(ActorCell.scala:1)
at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149) at akka.kamon.instrumentation.ActorMonitors$TrackedActor$$anonfun$processMessage$2.apply(ActorMonitor.scala:79)
at kamon.trace.Tracer$.withContext(TracerModule.scala:58)
at akka.kamon.instrumentation.ActorMonitors$TrackedActor.processMessage(ActorMonitor.scala:78) at akka.kamon.instrumentation.ActorCellInstrumentation.aroundBehaviourInvoke(ActorInstrumentation.scala:44)
at akka.actor.ActorCell.invoke(ActorCell.scala:488)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
at akka.dispatch.Mailbox.run(Mailbox.scala:224)
at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)



Is there any way to bind both?

Do I need to use only one at a moment?

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


--
     Read the docs: http://akka.io/docs/
     Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
     Search the archives: https://groups.google.com/group/akka-user
--- You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to