use of io.vertx.proton.ProtonClient in project vertx-proton by vert-x3.
the class VertxProtonExamples method example1.
public void example1(Vertx vertx) {
ProtonClient client = ProtonClient.create(vertx);
// Connect, then use the event loop thread to process things thereafter
client.connect("hostname", 5672, "username", "password", connectResult -> {
if (connectResult.succeeded()) {
connectResult.result().setContainer("my-container/client-id").openHandler(openResult -> {
if (openResult.succeeded()) {
ProtonConnection conn = openResult.result();
// Create senders, receivers etc..
}
}).open();
}
});
}
use of io.vertx.proton.ProtonClient in project hono by eclipse.
the class ConnectionFactoryImplTest method testConnectEnablesSslIfTrustStoreIsConfigured.
/**
* Verifies that the factory uses TLS when connecting to the peer if a trust store
* is configured but TLS has not been enabled explicitly.
*/
@SuppressWarnings("unchecked")
@Test
public void testConnectEnablesSslIfTrustStoreIsConfigured() {
// GIVEN a factory configured to use a specific trust store
final ClientConfigProperties config = new ClientConfigProperties();
config.setHost("remote.host");
config.setTrustStorePath("/tmp/trusted-ca.p12");
final ProtonClient client = mock(ProtonClient.class);
final ConnectionFactoryImpl factory = new ConnectionFactoryImpl(vertx, config);
factory.setProtonClient(client);
// WHEN connecting to the server
factory.connect(null, null, null, c -> {
});
// THEN the factory uses TLS when establishing the connection
final ArgumentCaptor<ProtonClientOptions> optionsCaptor = ArgumentCaptor.forClass(ProtonClientOptions.class);
verify(client).connect(optionsCaptor.capture(), eq("remote.host"), anyInt(), any(), any(), any(Handler.class));
assertTrue(optionsCaptor.getValue().isSsl());
}
use of io.vertx.proton.ProtonClient in project hono by eclipse.
the class ConnectionFactoryImplTest method testConnectDoesNotUseSaslPlainForEmptyUsernameAndPassword.
/**
* Verifies that the factory does not enable SASL_PLAIN if the username and password are empty
* strings.
*
* @param ctx The vert.x test context.
*/
@SuppressWarnings("unchecked")
@Test
public void testConnectDoesNotUseSaslPlainForEmptyUsernameAndPassword(final TestContext ctx) {
// GIVEN a factory configured to connect to a server
final ProtonClientOptions options = new ProtonClientOptions();
final ProtonClient client = mock(ProtonClient.class);
final ConnectionFactoryImpl factory = new ConnectionFactoryImpl(vertx, props);
factory.setProtonClient(client);
// WHEN connecting to the server using empty strings for username and password
factory.connect(options, "", "", null, null, c -> {
});
// THEN the factory does not enable the SASL_PLAIN mechanism when establishing
// the connection
ArgumentCaptor<ProtonClientOptions> optionsCaptor = ArgumentCaptor.forClass(ProtonClientOptions.class);
verify(client).connect(optionsCaptor.capture(), anyString(), anyInt(), eq(""), eq(""), any(Handler.class));
assertFalse(optionsCaptor.getValue().getEnabledSaslMechanisms().contains("PLAIN"));
}
Aggregations