Manivelpvn
Manivelpvn

Reputation: 13

Is it possible to map TCP and HTTP route to same spring boot application in Pivotal CF?

My application needs an TCP endpoint and HTTP endpoints, is it possible in PCF to have both the routes bind to same application?

Upvotes: 0

Views: 398

Answers (2)

Janne Valkealahti
Janne Valkealahti

Reputation: 2646

Looks like mappings to tcp ports are now possible but you need to use cf curl to access raw api's. Found this gist and it worked for me with pcf 2.0 running on gcp. gist

Upvotes: 0

Daniel Mikusa
Daniel Mikusa

Reputation: 15051

Is it possible to map TCP and HTTP route to same spring boot application in Pivotal CF?

I did a quick test and it worked for me.

$ cf app php-info-cf
Showing health and status for app php-info-cf in org cf-support / space dmikusa as [email protected]...

name:              php-info-cf
requested state:   started
instances:         1/1
usage:             128M x 1 instances
routes:            php-info-cf.cfapps.io, cf-tcpapps.io:3351
last uploaded:     Mon 26 Mar 09:18:59 EDT 2018
stack:             cflinuxfs2
buildpack:         https://github.com/dmikusa-pivotal/php-buildpack#v4.3.51_bonus

     state     since                  cpu    memory          disk         details
#0   running   2018-03-26T13:19:49Z   0.3%   23.8M of 128M   204M of 1G

Note the "routes:" row which lists an HTTP & TCP route.

That said, I'm not sure it's going to do exactly what you want. In the example above, both routes end up being directed to the same port in the app container. So an HTTP request to php-info.cfapps.io goes to the GoRouter which sends it to the app instance that is listening on port 8080 inside the container. Similarly, if you send an HTTP request to cf-tcpapps.io:3351 it will be routed to the same app instance which is also listening on port 8080 inside the container. The difference is that the second request won't go through the GoRouter. Both ultimately end up getting to your app listening on port 8080 though.

What you can't do at the moment is have your HTTP route go to port 8080 inside the container and have a TCP route go to port 8081 or some different port. Multiple listening ports inside an app container aren't supported at this time. You'd need two separate apps.

Upvotes: 2

Related Questions