client/src/main/java/io/hoplin/ConnectionStringParser.java
/**
   * Parse the connection string in format key1=value;key2=value
   * <pre>host=localhost;virtualHost=vhost1;username=user;password=secret</pre>
   *
   * @param connectionString the connection string to parse
   * @return the {@link RabbitMQOptions} created from the string
   */


@param connectionString the connection string to parse
@return the  RabbitMQOptions created from the string
@param connectionString the connection string to parse @return the RabbitMQOptions created from the string
public static RabbitMQOptions parse(final String connectionString) {
    Objects.requireNonNull(connectionString);
    final String[] parts = connectionString.split(";");
    final RabbitMQOptions options = new RabbitMQOptions();
    final boolean hostPresent = Arrays.stream(parts).anyMatch(p -> p.equalsIgnoreCase("host"));
    if (!hostPresent) {
      throw new HoplinRuntimeException("Required field 'host' is not present");
    }
    for (final String part : parts) {
      final String[] kv = part.split("=");
      if (kv.length != 2) {
        throw new HoplinRuntimeException(
            "Invalid KeyValue pair, expected connection string is in format 'host=localhost;virtualHost=vhost1' but got : "
                + part);
      }
      final String key = kv[0].trim();
      final String value = kv[1].trim();
      switch (key.toLowerCase()) {
        case "host":
          options.setHost(value);
          break;
        case "virtualhost":
          options.setVirtualHost(value);
          break;
        case "username":
          options.setUser(value);
          break;
        case "password":
          options.setPassword(value);
          break;
        case "requestedheartbeat":
          options.setRequestedHeartbeat(Integer.parseInt(value));
          break;
        case "timeout":
          options.setConnectionTimeout(Integer.parseInt(value));
          break;
        case "product":
          options.setClientProperty("product", value, true);
          break;
        case "platform":
          options.setClientProperty("platform", value, true);
          break;
        case "connectionretries":
          options.setConnectionRetries(Integer.parseInt(value));
          break;
        case "connectionretrydelay":
          options.setConnectionRetryDelay(Long.parseLong(value));
          break;
        default:
          throw new IllegalArgumentException("Unknown option : " + key);
      }
    }
    return options;
  }
public static RabbitMQOptions parse ( final String connectionString ) { Objects . requireNonNull ( connectionString ) ; final String [ ] parts = connectionString . split ( ";" ) ; final RabbitMQOptions options = new RabbitMQOptions ( ) ; final boolean hostPresent = Arrays . stream ( parts ) . anyMatch ( p -> p . equalsIgnoreCase ( "host" ) ) ; if ( ! hostPresent ) { throw new HoplinRuntimeException ( "Required field 'host' is not present" ) ; } for ( final String part : parts ) { final String [ ] kv = part . split ( "=" ) ; if ( kv . length != 2 ) { throw new HoplinRuntimeException ( "Invalid KeyValue pair, expected connection string is in format 'host=localhost;virtualHost=vhost1' but got : " + part ) ; } final String key = kv [ 0 ] . trim ( ) ; final String value = kv [ 1 ] . trim ( ) ; switch ( key . toLowerCase ( ) ) { case "host" : options . setHost ( value ) ; break ; case "virtualhost" : options . setVirtualHost ( value ) ; break ; case "username" : options . setUser ( value ) ; break ; case "password" : options . setPassword ( value ) ; break ; case "requestedheartbeat" : options . setRequestedHeartbeat ( Integer . parseInt ( value ) ) ; break ; case "timeout" : options . setConnectionTimeout ( Integer . parseInt ( value ) ) ; break ; case "product" : options . setClientProperty ( "product" , value , true ) ; break ; case "platform" : options . setClientProperty ( "platform" , value , true ) ; break ; case "connectionretries" : options . setConnectionRetries ( Integer . parseInt ( value ) ) ; break ; case "connectionretrydelay" : options . setConnectionRetryDelay ( Long . parseLong ( value ) ) ; break ; default : throw new IllegalArgumentException ( "Unknown option : " + key ) ; } } return options ; }
Parse the connection string in format key1=value;key2=value
 <pre>host=localhost;virtualHost=vhost1;username=user;password=secret</pre>
Parse the connection string in format key1 = value ; key2 = value <pre > host = localhost ; virtualHost = vhost1 ; username = user ; password = secret< / pre >
// check for required fields