Upcoming Feature: Payara Micro HTTP & HTTPS auto-binding

Photo of Andrew Pielage by Andrew Pielage
fish_3_large.jpgTaking inspiration from the way the integrated Hazelcast automatically searches for an open port when clustering, I decided to add in a similar feature for Payara Micro when trying to bind its HTTP and HTTPS ports.


In the upcoming Payara 4.1.153 release, Payara Micro will be shipping with support for the first working iteration of this new feature. To help and keep Payara as a drop-in replacement for GlassFish though, the auto-binding is not enabled by default, and is instead enabled by passing in an extra option when starting Payara Micro.

The three new Payara Micro options pertaining to this feature are:
  • --autoBindHttp – Enables auto-bind functionality for the HTTP port
  • --autoBindSsl – Enables auto-bind functionality for the HTTPS port
  • --autoBindRange – Sets the range for the auto-bind feature
 The feature works in how you may have seen the Hazelcast clustering working; when the auto-bind feature is enabled, Payara Micro will attempt to connect to the specified port, and if that port is busy, it will instead try to bind on the next port up, repeating until it finds a port, or the --autoBindRange limiter is reached.
It’s super easy to use, you just have to set the respective auto-bind option to true for the HTTP and/or SSL port:
java -jar payara-micro.jar --autoBindHttp
To grant some control over how the auto-bind feature works, I created the --autoBindRange option. This option allows you to determine how many ports to attempt binding to before giving up. This option defaults to 5 if not specified.As an example:
java -jar payara-micro.jar --port 8080 --autoBindHttp --autoBindRange 3
This will have Payara Micro attempt to find a free port on port 8080, then 8081, 8082, and 8083 before giving up and failing to start.In its current form, the auto-bind feature assumes that the default port is 8080 for HTTP, and 8181 for SSL; the feature will not release with the capability of reading values set in a domain.xml file. Having the auto-bind feature read the HTTP and HTTPS port values from a domain.xml is something we’ll be looking at for a future release.If you want to check out the source code for this, check out the pull request here: https://github.com/payara/Payara/pull/359/filesIf you have any ideas for how to improve this, or any other feature in Payara, please consider raising an issue on our GitHub project page!


Related Posts