alpakka icon indicating copy to clipboard operation
alpakka copied to clipboard

Bring up HTTP Server on Unix Domain Socker with alpakka

Open scheruku-in opened this issue 1 year ago • 0 comments

Hello, I am trying to bring up REST API server on UDS with alpakka as documented in https://doc.akka.io/docs/alpakka/current/unix-domain-socket.html# Here is the sample code .

        val serverSideFlow = Flow[ByteString]
          .buffer(1, OverflowStrategy.backpressure)
          .wireTap(bytes => received.success(bytes))
        UnixDomainSocket().bindAndHandle(serverSideFlow, Paths.get(socketPath))

It seems to start the server on UDS but not sure how to specify the routes as the above example doesn't seem to accept route info.

netstat -anp| grep "LISTEN"
tcp6       0      0 :::16501                :::*                    LISTEN      49/java             
tcp6       0      0 172.30.187.35:36885     :::*                    LISTEN      49/java             
tcp6       0      0 172.30.187.35:42999     :::*                    LISTEN      49/java                   
tcp6       0      0 :::32841                :::*                    LISTEN      49/java             
tcp6       0      0 :::39053                :::*                    LISTEN      49/java             
unix  2      [ ACC ]     STREAM     LISTENING     899427761 49/java              /tmp/.java_pid49.tmp
unix  2      [ ACC ]     STREAM     LISTENING     899404587 49/java              /tmp/uds-socket/uds.sock

Trying to access using socket file hangs.

 curl -k -v -X GET "http://localhost" --unix-socket /tmp/uds-socket/uds.sock
Note: Unnecessary use of -X or --request, GET is already inferred.
* Rebuilt URL to: http://localhost/
*   Trying /tmp/uds-socket/uds.sock...
* Connected to localhost (/tmp/uds-socket/uds.sock) port 80 (#0)
> GET / HTTP/1.1
> Host: localhost
> User-Agent: curl/7.61.1
> Accept: */*

I found few examples for accessing a REST endpoint which is already exposed on a particular socket path (ex: https://stackoverflow.com/questions/51565935/how-to-access-rest-api-on-a-unix-domain-socket-with-akka-http-or-alpakka), but I haven't come across any sample on hosting REST end points on UDS using alpakka or akka-http.

Would you please let me know if its possible? If yes, kindly share the sample.

Regards, Sobha

scheruku-in avatar Jul 26 '22 05:07 scheruku-in