/** * Options can be used to set the server URL, or multiple URLS, callback * handlers for various errors, and connection events. * * * <p>This is a synchronous call, and the connection should be ready for use on return * there are network timing issues that could result in a successful connect call but * the connection is invalid soon after return, where soon is in the network/thread world. * * <p>If the connection fails, an IOException is thrown * * @param options the options object to use to create the connection * @throws IOException if a networking issue occurs * @throws InterruptedException if the current thread is interrupted * @return the connection */ public static Connection connect(Options options) throws IOException, InterruptedException { return createConnection(options, false); }
/** * Options can be used to set the server URL, or multiple URLS, callback * handlers for various errors, and connection events. * * * <p>This is a synchronous call, and the connection should be ready for use on return * there are network timing issues that could result in a successful connect call but * the connection is invalid soon after return, where soon is in the network/thread world. * * <p>If the connection fails, an IOException is thrown * * @param options the options object to use to create the connection * @throws IOException if a networking issue occurs * @throws InterruptedException if the current thread is interrupted * @return the connection */ public static Connection connect(Options options) throws IOException, InterruptedException { return createConnection(options, false); }
/** * Connect to the default URL, {@link Options#DEFAULT_URL Options.DEFAULT_URL}, with all of the * default options. * * <p>This is a synchronous call, and the connection should be ready for use on return * there are network timing issues that could result in a successful connect call but * the connection is invalid soon after return, where soon is in the network/thread world. * * <p>If the connection fails, an IOException is thrown * * @throws IOException if a networking issue occurs * @throws InterruptedException if the current thread is interrupted * @return the connection */ public static Connection connect() throws IOException, InterruptedException { Options options = new Options.Builder().server(Options.DEFAULT_URL).build(); return createConnection(options, false); }
/** * Connect to the default URL, {@link Options#DEFAULT_URL Options.DEFAULT_URL}, with all of the * default options. * * <p>This is a synchronous call, and the connection should be ready for use on return * there are network timing issues that could result in a successful connect call but * the connection is invalid soon after return, where soon is in the network/thread world. * * <p>If the connection fails, an IOException is thrown * * @throws IOException if a networking issue occurs * @throws InterruptedException if the current thread is interrupted * @return the connection */ public static Connection connect() throws IOException, InterruptedException { Options options = new Options.Builder().server(Options.DEFAULT_URL).build(); return createConnection(options, false); }
/** * The Java client generally expects URLs of the form {@code nats://hostname:port} * * <p>but also allows urls with a user password {@code nats://user:pass@hostname:port}. * * <p>or token in them {@code nats://token@hostname:port}. * * <p>Moreover, you can initiate a TLS connection, by using the `tls` * schema, which will use the default SSLContext, or fail if one is not set. For * testing and development, the `opentls` schema is support when the server is * in non-verify mode. In this case, the client will accept any server * certificate and will not provide one of its own. * * <p>This is a synchronous call, and the connection should be ready for use on return * there are network timing issues that could result in a successful connect call but * the connection is invalid soon after return, where soon is in the network/thread world. * * <p>If the connection fails, an IOException is thrown * * @param url the url of the server, ie. nats://localhost:4222 * @throws IOException if a networking issue occurs * @throws InterruptedException if the current thread is interrupted * @return the connection */ public static Connection connect(String url) throws IOException, InterruptedException { Options options = new Options.Builder().server(url).build(); return createConnection(options, false); }
/** * The Java client generally expects URLs of the form {@code nats://hostname:port} * * <p>but also allows urls with a user password {@code nats://user:pass@hostname:port}. * * <p>or token in them {@code nats://token@hostname:port}. * * <p>Moreover, you can initiate a TLS connection, by using the `tls` * schema, which will use the default SSLContext, or fail if one is not set. For * testing and development, the `opentls` schema is support when the server is * in non-verify mode. In this case, the client will accept any server * certificate and will not provide one of its own. * * <p>This is a synchronous call, and the connection should be ready for use on return * there are network timing issues that could result in a successful connect call but * the connection is invalid soon after return, where soon is in the network/thread world. * * <p>If the connection fails, an IOException is thrown * * @param url the url of the server, ie. nats://localhost:4222 * @throws IOException if a networking issue occurs * @throws InterruptedException if the current thread is interrupted * @return the connection */ public static Connection connect(String url) throws IOException, InterruptedException { Options options = new Options.Builder().server(url).build(); return createConnection(options, false); }