Search in sources :

Example 6 with ProtonClient

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();
        }
    });
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) Section(org.apache.qpid.proton.amqp.messaging.Section) Source(io.vertx.docgen.Source) ProtonHelper.message(io.vertx.proton.ProtonHelper.message) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Vertx(io.vertx.core.Vertx) ProtonSender(io.vertx.proton.ProtonSender) Message(org.apache.qpid.proton.message.Message) ProtonClient(io.vertx.proton.ProtonClient) Context(io.vertx.core.Context) ProtonConnection(io.vertx.proton.ProtonConnection) ProtonClient(io.vertx.proton.ProtonClient)

Example 7 with ProtonClient

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());
}
Also used : Handler(io.vertx.core.Handler) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) ProtonClient(io.vertx.proton.ProtonClient) Test(org.junit.Test)

Example 8 with ProtonClient

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"));
}
Also used : Handler(io.vertx.core.Handler) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) ProtonClient(io.vertx.proton.ProtonClient) Test(org.junit.Test)

Aggregations

ProtonClient (io.vertx.proton.ProtonClient)8 ProtonClientOptions (io.vertx.proton.ProtonClientOptions)5 Handler (io.vertx.core.Handler)4 Test (org.junit.Test)4 ProtonConnection (io.vertx.proton.ProtonConnection)3 Vertx (io.vertx.core.Vertx)2 ClientConfigProperties (org.eclipse.hono.config.ClientConfigProperties)2 Context (io.vertx.core.Context)1 Source (io.vertx.docgen.Source)1 Async (io.vertx.ext.unit.Async)1 ProtonHelper.message (io.vertx.proton.ProtonHelper.message)1 ProtonSender (io.vertx.proton.ProtonSender)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)1 Section (org.apache.qpid.proton.amqp.messaging.Section)1 Message (org.apache.qpid.proton.message.Message)1