src/main/java/io/arivera/oss/embedded/rabbitmq/util/RandomPortSupplier.java
public int get() throws IllegalStateException {
    ServerSocket socket = null;
    try {
      socket = this.severSocketFactory.createServerSocket(0);
      socket.setReuseAddress(false);
      return socket.getLocalPort();
    } catch (IOException e) {
      throw new IllegalStateException("Could not determine random port to assign.", e);
    } finally {
      if (socket != null) {
        try {
          socket.close();
        } catch (IOException e) {
          LOGGER.debug("Couldn't close socket that was temporarily opened to determine random port.", e);
        }
      }
    }
  }
public int get() throws IllegalStateException {
    ServerSocket socket = null;
    try {
      socket = this.severSocketFactory.createServerSocket(0);
      socket.setReuseAddress(false);
      return socket.getLocalPort();
    } catch (IOException e) {
      throw new IllegalStateException("Could not determine random port to assign.", e);
    } finally {
      if (socket != null) {
        try {
          socket.close();
        } catch (IOException e) {
          LOGGER.debug("Couldn't close socket that was temporarily opened to determine random port.", e);
        }
      }
    }
  }
@return an available port assigned at random by the OS.

@throws IllegalStateException if the port cannot be determined.