Search in sources :

Example 41 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver in project hono by eclipse.

the class AuthenticationServerClient method openReceiver.

private static Future<ProtonReceiver> openReceiver(final ProtonConnection openConnection, final ProtonMessageHandler messageHandler) {
    final Promise<ProtonReceiver> result = Promise.promise();
    final ProtonReceiver recv = openConnection.createReceiver(AuthenticationConstants.ENDPOINT_NAME_AUTHENTICATION);
    recv.openHandler(result);
    recv.handler(messageHandler);
    recv.open();
    return result.future();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver)

Example 42 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver in project vertx-proton by vert-x3.

the class ProtonReceiverImplTest method testFlowWithExistingDrainOutstandingThrowsISE.

@Test
public void testFlowWithExistingDrainOutstandingThrowsISE() {
    ProtonConnectionImpl conn = new ProtonConnectionImpl(null, null, null);
    conn.bindClient(null, Mockito.mock(NetSocketInternal.class), null, new ProtonTransportOptions());
    conn.fireDisconnect();
    ProtonReceiver receiver = conn.createReceiver("address");
    AtomicBoolean drain1complete = new AtomicBoolean();
    receiver.setPrefetch(0);
    receiver.flow(1);
    receiver.drain(0, h -> {
        drain1complete.set(true);
    });
    try {
        receiver.flow(1);
        fail("should have thrown due to outstanding drain operation");
    } catch (IllegalStateException ise) {
        // Expected
        assertFalse("drain should not have been completed", drain1complete.get());
    }
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProtonTransportOptions(io.vertx.proton.ProtonTransportOptions) NetSocketInternal(io.vertx.core.net.impl.NetSocketInternal) Test(org.junit.Test)

Example 43 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver in project vertx-proton by vert-x3.

the class ProtonReceiverImplTest method testDrainWithExistingDrainOutstandingThrowsISE.

@Test
public void testDrainWithExistingDrainOutstandingThrowsISE() {
    ProtonConnectionImpl conn = new ProtonConnectionImpl(null, null, null);
    conn.bindClient(null, Mockito.mock(NetSocketInternal.class), null, new ProtonTransportOptions());
    conn.fireDisconnect();
    ProtonReceiver receiver = conn.createReceiver("address");
    AtomicBoolean drain1complete = new AtomicBoolean();
    receiver.setPrefetch(0);
    receiver.flow(1);
    receiver.drain(0, h -> {
        drain1complete.set(true);
    });
    try {
        receiver.drain(0, h2 -> {
        });
        fail("should have thrown due to outstanding drain operation");
    } catch (IllegalStateException ise) {
        // Expected
        assertFalse("first drain should not have been completed", drain1complete.get());
    }
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProtonTransportOptions(io.vertx.proton.ProtonTransportOptions) NetSocketInternal(io.vertx.core.net.impl.NetSocketInternal) Test(org.junit.Test)

Example 44 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver in project enmasse-workshop by EnMasseProject.

the class AmqpClient method receive.

@Override
public void receive(String address) {
    this.vertx.runOnContext(c -> {
        if (!this.receivers.containsKey(address)) {
            final ProtonReceiver receiver = this.connection.createReceiver(address);
            receiver.handler((delivery, message) -> {
                this.receiverHandler(receiver, delivery, message);
            });
            receiver.open();
        }
    });
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver)

Example 45 with ProtonReceiver

use of io.vertx.proton.ProtonReceiver in project vertx-examples by vert-x3.

the class ReconnectReceiver method setupReceiver.

private void setupReceiver(ProtonConnection connection) {
    ProtonReceiver receiver = connection.createReceiver(ADDRESS);
    receiver.handler((delivery, msg) -> {
        String content = (String) ((AmqpValue) msg.getBody()).getValue();
        System.out.println("Received message with content: " + content);
    // By default, receivers automatically accept (and settle) the delivery
    // when the handler returns, if no other disposition has been applied.
    // To change this and always manage dispositions yourself, use the
    // setAutoAccept method on the receiver.
    }).open();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonConnection(io.vertx.proton.ProtonConnection) ProtonReceiver(io.vertx.proton.ProtonReceiver) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) AbstractVerticle(io.vertx.core.AbstractVerticle) Vertx(io.vertx.core.Vertx) ProtonClient(io.vertx.proton.ProtonClient) Instant(java.time.Instant) Runner(io.vertx.example.util.Runner) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue)

Aggregations

ProtonReceiver (io.vertx.proton.ProtonReceiver)45 ProtonConnection (io.vertx.proton.ProtonConnection)19 ProtonMessageHandler (io.vertx.proton.ProtonMessageHandler)19 Vertx (io.vertx.core.Vertx)17 ProtonQoS (io.vertx.proton.ProtonQoS)16 Handler (io.vertx.core.Handler)13 ProtonSender (io.vertx.proton.ProtonSender)13 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)13 Message (org.apache.qpid.proton.message.Message)12 Future (io.vertx.core.Future)11 BeforeEach (org.junit.jupiter.api.BeforeEach)11 ProtonDelivery (io.vertx.proton.ProtonDelivery)10 HttpURLConnection (java.net.HttpURLConnection)10 ClientErrorException (org.eclipse.hono.client.ClientErrorException)10 ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)10 Test (org.junit.jupiter.api.Test)10 AsyncResult (io.vertx.core.AsyncResult)9 Promise (io.vertx.core.Promise)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9