Search in sources :

Example 1 with ConsumerBase

use of org.apache.pulsar.client.impl.ConsumerBase in project incubator-pulsar by apache.

the class ResendRequestTest method printIncomingMessageQueue.

@SuppressWarnings("unchecked")
private BlockingQueue<Message<byte[]>> printIncomingMessageQueue(Consumer<byte[]> consumer) throws Exception {
    BlockingQueue<Message<byte[]>> imq = null;
    ConsumerBase<byte[]> c = (ConsumerBase<byte[]>) consumer;
    Field field = ConsumerBase.class.getDeclaredField("incomingMessages");
    field.setAccessible(true);
    imq = (BlockingQueue<Message<byte[]>>) field.get(c);
    log.info("Incoming MEssage Queue: {}", imq);
    return imq;
}
Also used : Field(java.lang.reflect.Field) ConsumerBase(org.apache.pulsar.client.impl.ConsumerBase) Message(org.apache.pulsar.client.api.Message)

Example 2 with ConsumerBase

use of org.apache.pulsar.client.impl.ConsumerBase in project incubator-pulsar by apache.

the class ClientErrorsTest method subscribeFailDoesNotFailOtherConsumer.

private void subscribeFailDoesNotFailOtherConsumer(String topic1, String topic2) throws Exception {
    PulsarClient client = PulsarClient.builder().serviceUrl("http://127.0.0.1:" + WEB_SERVICE_PORT).build();
    final AtomicInteger counter = new AtomicInteger(0);
    mockBrokerService.setHandleSubscribe((ctx, subscribe) -> {
        if (counter.incrementAndGet() == 2) {
            // fail second producer
            ctx.writeAndFlush(Commands.newError(subscribe.getRequestId(), ServerError.AuthenticationError, "msg"));
            return;
        }
        ctx.writeAndFlush(Commands.newSuccess(subscribe.getRequestId()));
    });
    ConsumerBase<byte[]> consumer1 = (ConsumerBase<byte[]>) client.newConsumer().topic(topic1).subscriptionName("sub1").subscribe();
    ConsumerBase<byte[]> consumer2 = null;
    try {
        consumer2 = (ConsumerBase<byte[]>) client.newConsumer().topic(topic2).subscriptionName("sub1").subscribe();
        fail("Should have failed");
    } catch (Exception e) {
    // ok
    }
    assertTrue(consumer1.isConnected());
    assertFalse(consumer2 != null && consumer2.isConnected());
    mockBrokerService.resetHandleSubscribe();
    client.close();
}
Also used : ConsumerBase(org.apache.pulsar.client.impl.ConsumerBase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LookupException(org.apache.pulsar.client.api.PulsarClientException.LookupException)

Aggregations

ConsumerBase (org.apache.pulsar.client.impl.ConsumerBase)2 Field (java.lang.reflect.Field)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Message (org.apache.pulsar.client.api.Message)1 LookupException (org.apache.pulsar.client.api.PulsarClientException.LookupException)1