当前位置: 首页>>代码示例>>Java>>正文


Java SubscriptionType类代码示例

本文整理汇总了Java中org.apache.pulsar.client.api.SubscriptionType的典型用法代码示例。如果您正苦于以下问题:Java SubscriptionType类的具体用法?Java SubscriptionType怎么用?Java SubscriptionType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

SubscriptionType类属于org.apache.pulsar.client.api包,在下文中一共展示了SubscriptionType类的40个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getConsumerConfiguration

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
private ConsumerConfiguration getConsumerConfiguration() {
    ConsumerConfiguration conf = new ConsumerConfiguration();

    if (queryParams.containsKey("ackTimeoutMillis")) {
        conf.setAckTimeout(Integer.parseInt(queryParams.get("ackTimeoutMillis")), TimeUnit.MILLISECONDS);
    }

    if (queryParams.containsKey("subscriptionType")) {
        checkArgument(Enums.getIfPresent(SubscriptionType.class, queryParams.get("subscriptionType")).isPresent(),
                "Invalid subscriptionType %s", queryParams.get("subscriptionType"));
        conf.setSubscriptionType(SubscriptionType.valueOf(queryParams.get("subscriptionType")));
    }

    if (queryParams.containsKey("receiverQueueSize")) {
        conf.setReceiverQueueSize(Math.min(Integer.parseInt(queryParams.get("receiverQueueSize")), 1000));
    }

    if (queryParams.containsKey("consumerName")) {
        conf.setConsumerName(queryParams.get("consumerName"));
    }

    return conf;
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:24,代码来源:ConsumerHandler.java


示例2: testMockBrokerService

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testMockBrokerService() throws Exception {
    // test default actions of mock broker service
    try {
        PulsarClient client = PulsarClient.create("http://127.0.0.1:" + WEB_SERVICE_PORT);

        ConsumerConfiguration conf = new ConsumerConfiguration();
        conf.setSubscriptionType(SubscriptionType.Exclusive);
        Consumer consumer = client.subscribe("persistent://prop/use/ns/t1", "sub1", conf);

        Producer producer = client.createProducer("persistent://prop/use/ns/t1");
        Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
        producer.send("message".getBytes());
        Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);

        consumer.unsubscribe();

        producer.close();
        consumer.close();
        client.close();
    } catch (Exception e) {
        fail("None of the mocked operations should throw a client side exception");
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:25,代码来源:ClientErrorsTest.java


示例3: subscribeSuccessAfterRetry

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
private void subscribeSuccessAfterRetry(String topic) throws Exception {
    PulsarClient client = PulsarClient.create("http://127.0.0.1:" + WEB_SERVICE_PORT);
    final AtomicInteger counter = new AtomicInteger(0);

    mockBrokerService.setHandleSubscribe((ctx, subscribe) -> {
        if (counter.incrementAndGet() == 2) {
            ctx.writeAndFlush(Commands.newSuccess(subscribe.getRequestId()));
            return;
        }
        ctx.writeAndFlush(Commands.newError(subscribe.getRequestId(), ServerError.ServiceNotReady, "msg"));
    });

    try {
        ConsumerConfiguration conf = new ConsumerConfiguration();
        conf.setSubscriptionType(SubscriptionType.Exclusive);
        Consumer consumer = client.subscribe(topic, "sub1", conf);
    } catch (Exception e) {
        fail("Should not fail");
    }

    mockBrokerService.resetHandleSubscribe();
    client.close();
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:24,代码来源:ClientErrorsTest.java


示例4: subscribeFailDoesNotFailOtherConsumer

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
private void subscribeFailDoesNotFailOtherConsumer(String topic1, String topic2) throws Exception {
    PulsarClient client = PulsarClient.create("http://127.0.0.1:" + WEB_SERVICE_PORT);
    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()));

    });

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    ConsumerBase consumer1 = (ConsumerBase) client.subscribe(topic1, "sub1", conf);

    ConsumerBase consumer2 = null;
    try {
        consumer2 = (ConsumerBase) client.subscribe(topic2, "sub1", conf);
        fail("Should have failed");
    } catch (Exception e) {
        // ok
    }

    assertTrue(consumer1.isConnected());
    assertFalse(consumer2 != null && consumer2.isConnected());

    mockBrokerService.resetHandleSubscribe();
    client.close();
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:33,代码来源:ClientErrorsTest.java


示例5: testSingleClientMultipleSubscriptions

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testSingleClientMultipleSubscriptions() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/topic6";
    final String subName = "sub6";

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);

    pulsarClient.subscribe(topicName, subName, conf);
    pulsarClient.createProducer(topicName);
    try {
        pulsarClient.subscribe(topicName, subName, conf);
        fail("Should have thrown an exception since one consumer is already connected");
    } catch (PulsarClientException cce) {
        Assert.assertTrue(cce.getMessage().contains("Exclusive consumer is already connected"));
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:18,代码来源:PersistentTopicE2ETest.java


示例6: testMultipleClientsMultipleSubscriptions

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testMultipleClientsMultipleSubscriptions() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/topic7";
    final String subName = "sub7";

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);

    PulsarClient client1 = PulsarClient.create(brokerUrl.toString());
    PulsarClient client2 = PulsarClient.create(brokerUrl.toString());

    try {
        client1.subscribe(topicName, subName, conf);
        client1.createProducer(topicName);

        client2.createProducer(topicName);

        client2.subscribe(topicName, subName, conf);
        fail("Should have thrown an exception since one consumer is already connected");
    } catch (PulsarClientException cce) {
        Assert.assertTrue(cce.getMessage().contains("Exclusive consumer is already connected"));
    } finally {
        client2.shutdown();
        client1.shutdown();
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:27,代码来源:PersistentTopicE2ETest.java


示例7: setup

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Override
protected void setup() throws Exception {
    super.internalSetup();
    super.producerBaseSetup();

    pulsarSpoutConf = new PulsarSpoutConfiguration();
    pulsarSpoutConf.setServiceUrl(serviceUrl);
    pulsarSpoutConf.setTopic(topic);
    pulsarSpoutConf.setSubscriptionName(subscriptionName);
    pulsarSpoutConf.setMessageToValuesMapper(messageToValuesMapper);
    pulsarSpoutConf.setFailedRetriesTimeout(1, TimeUnit.SECONDS);
    pulsarSpoutConf.setMaxFailedRetries(2);
    pulsarSpoutConf.setSharedConsumerEnabled(true);
    pulsarSpoutConf.setMetricsTimeIntervalInSecs(60);
    consumerConf = new ConsumerConfiguration();
    consumerConf.setSubscriptionType(SubscriptionType.Shared);
    spout = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration(), consumerConf);
    mockCollector = new MockSpoutOutputCollector();
    SpoutOutputCollector collector = new SpoutOutputCollector(mockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-spout-" + methodName);
    when(context.getThisTaskId()).thenReturn(0);
    spout.open(Maps.newHashMap(), context, collector);
    producer = pulsarClient.createProducer(topic);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:26,代码来源:PulsarSpoutTest.java


示例8: testFailedConsumer

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testFailedConsumer() throws Exception {
    PulsarSpoutConfiguration pulsarSpoutConf = new PulsarSpoutConfiguration();
    pulsarSpoutConf.setServiceUrl(serviceUrl);
    pulsarSpoutConf.setTopic("persistent://invalidTopic");
    pulsarSpoutConf.setSubscriptionName(subscriptionName);
    pulsarSpoutConf.setMessageToValuesMapper(messageToValuesMapper);
    pulsarSpoutConf.setFailedRetriesTimeout(1, TimeUnit.SECONDS);
    pulsarSpoutConf.setMaxFailedRetries(2);
    pulsarSpoutConf.setSharedConsumerEnabled(false);
    pulsarSpoutConf.setMetricsTimeIntervalInSecs(60);
    ConsumerConfiguration consumerConf = new ConsumerConfiguration();
    consumerConf.setSubscriptionType(SubscriptionType.Shared);
    PulsarSpout spout = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration(), consumerConf);
    MockSpoutOutputCollector mockCollector = new MockSpoutOutputCollector();
    SpoutOutputCollector collector = new SpoutOutputCollector(mockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("new-test" + methodName);
    when(context.getThisTaskId()).thenReturn(0);
    try {
        spout.open(Maps.newHashMap(), context, collector);
        fail("should have failed as consumer creation failed");
    } catch (IllegalStateException e) {
        // Ok
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:27,代码来源:PulsarSpoutTest.java


示例9: getSubType

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
protected SubType getSubType() {
    SubscriptionType type = conf.getSubscriptionType();
    switch (type) {
    case Exclusive:
        return SubType.Exclusive;

    case Shared:
        return SubType.Shared;

    case Failover:
        return SubType.Failover;
    }

    // Should not happen since we cover all cases above
    return null;
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:17,代码来源:ConsumerBase.java


示例10: main

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
    // Create a Pulsar client instance. A single instance can be shared across many
    // producers and consumer within the same application
    PulsarClient client = PulsarClient.create(SERVICE_URL);

    // Here you get the chance to configure consumer specific settings. eg:
    ConsumerConfiguration conf = new ConsumerConfiguration();

    // Allow multiple consumers to attache to the same subscription
    // and get messages dispatched as a Queue
    conf.setSubscriptionType(SubscriptionType.Shared);

    // Once the consumer is created, it can be used for the entire application life-cycle
    Consumer consumer = client.subscribe(TOPIC_NAME, SUBSCRIPTION_NAME, conf);
    log.info("Created Pulsar consumer");

    while (true) {
        // Wait until a message is available
        Message msg = consumer.receive();

        // Do something with the message
        String content = new String(msg.getData());
        log.info("Received message '{}' with msg-id={}", content, msg.getMessageId());

        // Acknowledge processing of message so that it can be deleted
        consumer.acknowledge(msg);
    }
}
 
开发者ID:streamlio,项目名称:pulsar-java-tutorial,代码行数:29,代码来源:ConsumerTutorial.java


示例11: RawReaderImpl

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
public RawReaderImpl(PulsarClientImpl client, String topic, String subscription,
                     CompletableFuture<Consumer> consumerFuture) {
    this.client = client;
    this.subscription = subscription;
    this.topic = topic;

    consumerConfiguration = new ConsumerConfiguration();
    consumerConfiguration.setSubscriptionType(SubscriptionType.Exclusive);
    consumerConfiguration.setReceiverQueueSize(DEFAULT_RECEIVER_QUEUE_SIZE);

    consumer = new RawConsumerImpl(client, topic, subscription, consumerConfiguration,
                                   consumerFuture);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:14,代码来源:RawReaderImpl.java


示例12: testBatchMessagesRateOut

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
public void testBatchMessagesRateOut() throws PulsarClientException, InterruptedException, PulsarAdminException {
    log.info("-- Starting {} test --", methodName);
    String topicName = "persistent://my-property/cluster/my-ns/testBatchMessagesRateOut";
    double produceRate = 17;
    int batchSize = 5;
    ConsumerConfiguration consumerConf = new ConsumerConfiguration();
    consumerConf.setSubscriptionType(SubscriptionType.Exclusive);
    Consumer consumer = pulsarClient.subscribe(topicName, "my-subscriber-name", consumerConf);
    ProducerConfiguration producerConf = new ProducerConfiguration();
    producerConf.setBatchingMaxMessages(batchSize);
    producerConf.setBatchingEnabled(true);
    producerConf.setBatchingMaxPublishDelay(2, TimeUnit.SECONDS);

    Producer producer = pulsarClient.createProducer(topicName, producerConf);
    AtomicBoolean runTest = new AtomicBoolean(true);
    Thread t1 = new Thread(() -> {
        RateLimiter r = RateLimiter.create(produceRate);
        while (runTest.get()) {
            r.acquire();
            producer.sendAsync("Hello World".getBytes());
            consumer.receiveAsync().thenAccept(message -> consumer.acknowledgeAsync(message));
        }
    });
    t1.start();
    Thread.sleep(2000); // Two seconds sleep
    runTest.set(false);
    pulsar.getBrokerService().updateRates();
    double actualRate = admin.persistentTopics().getStats(topicName).msgRateOut;
    assertTrue(actualRate > (produceRate / batchSize));
    consumer.unsubscribe();
    log.info("-- Exiting {} test --", methodName);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:33,代码来源:SimpleProducerConsumerStatTest.java


示例13: testLookupWithDisconnection

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testLookupWithDisconnection() throws Exception {
    final String brokerUrl = "pulsar://127.0.0.1:" + BROKER_SERVICE_PORT;
    PulsarClient client = PulsarClient.create(brokerUrl);
    final AtomicInteger counter = new AtomicInteger(0);
    String topic = "persistent://prop/use/ns/t1";

    mockBrokerService.setHandlePartitionLookup((ctx, lookup) -> {
        ctx.writeAndFlush(Commands.newPartitionMetadataResponse(0, lookup.getRequestId()));
    });

    mockBrokerService.setHandleLookup((ctx, lookup) -> {
        if (counter.incrementAndGet() == 1) {
            // piggyback unknown error to relay assertion failure
            ctx.close();
            return;
        }
        ctx.writeAndFlush(Commands.newLookupResponse(brokerUrl, null, true, LookupType.Connect,
                lookup.getRequestId(), false));
    });

    try {
        ConsumerConfiguration conf = new ConsumerConfiguration();
        conf.setSubscriptionType(SubscriptionType.Exclusive);
        Consumer consumer = client.subscribe(topic, "sub1", conf);
    } catch (Exception e) {
        if (e.getMessage().equals(ASSERTION_ERROR)) {
            fail("Subscribe should not retry on persistence error");
        }
        assertTrue(e instanceof PulsarClientException.BrokerPersistenceException);
    }
    mockBrokerService.resetHandlePartitionLookup();
    mockBrokerService.resetHandleLookup();
    client.close();

}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:37,代码来源:ClientErrorsTest.java


示例14: subscribeFailWithoutRetry

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
private void subscribeFailWithoutRetry(String topic) throws Exception {
    PulsarClient client = PulsarClient.create("http://127.0.0.1:" + WEB_SERVICE_PORT);
    final AtomicInteger counter = new AtomicInteger(0);

    mockBrokerService.setHandleSubscribe((ctx, subscribe) -> {
        if (counter.incrementAndGet() == 2) {
            // piggyback unknown error to relay assertion failure
            ctx.writeAndFlush(
                    Commands.newError(subscribe.getRequestId(), ServerError.UnknownError, ASSERTION_ERROR));
            return;
        }
        ctx.writeAndFlush(Commands.newError(subscribe.getRequestId(), ServerError.PersistenceError, "msg"));
    });

    try {
        ConsumerConfiguration conf = new ConsumerConfiguration();
        conf.setSubscriptionType(SubscriptionType.Exclusive);
        Consumer consumer = client.subscribe(topic, "sub1", conf);
    } catch (Exception e) {
        if (e.getMessage().equals(ASSERTION_ERROR)) {
            fail("Subscribe should not retry on persistence error");
        }
        assertTrue(e instanceof PulsarClientException.BrokerPersistenceException);
    }
    mockBrokerService.resetHandleSubscribe();
    client.close();
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:28,代码来源:ClientErrorsTest.java


示例15: testSyncProducerAndConsumer

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
public void testSyncProducerAndConsumer(int batchMessageDelayMs) throws Exception {
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    Consumer consumer = pulsarClient.subscribe("persistent://my-property/use/my-ns/my-topic", "my-subscriber-name",
            conf);

    ProducerConfiguration producerConf = new ProducerConfiguration();

    if (batchMessageDelayMs != 0) {
        producerConf.setBatchingEnabled(true);
        producerConf.setBatchingMaxPublishDelay(batchMessageDelayMs, TimeUnit.MILLISECONDS);
        producerConf.setBatchingMaxMessages(5);
    }

    Producer producer = pulsarClient.createProducer("persistent://my-property/use/my-ns/my-topic", producerConf);
    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }

    Message msg = null;
    Set<String> messageSet = Sets.newHashSet();
    for (int i = 0; i < 10; i++) {
        msg = consumer.receive(5, TimeUnit.SECONDS);
        String receivedMessage = new String(msg.getData());
        log.debug("Received message: [{}]", receivedMessage);
        String expectedMessage = "my-message-" + i;
        testMessageOrderAndDuplicates(messageSet, receivedMessage, expectedMessage);
    }
    // Acknowledge the consumption of all messages at once
    consumer.acknowledgeCumulative(msg);
    consumer.close();
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:34,代码来源:AuthenticatedProducerConsumerTest.java


示例16: testFailedZeroQueueSizeBatchMessage

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test()
public void testFailedZeroQueueSizeBatchMessage() throws PulsarClientException {

    int batchMessageDelayMs = 100;
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Shared);
    conf.setReceiverQueueSize(0);
    Consumer consumer = pulsarClient.subscribe("persistent://prop-xyz/use/ns-abc/topic1", "my-subscriber-name",
            conf);

    ProducerConfiguration producerConf = new ProducerConfiguration();

    if (batchMessageDelayMs != 0) {
        producerConf.setBatchingEnabled(true);
        producerConf.setBatchingMaxPublishDelay(batchMessageDelayMs, TimeUnit.MILLISECONDS);
        producerConf.setBatchingMaxMessages(5);
    }

    Producer producer = pulsarClient.createProducer("persistent://prop-xyz/use/ns-abc/topic1", producerConf);
    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }

    try {
        consumer.receiveAsync().handle((ok, e) -> {
            if (e == null) {
                // as zero receiverQueueSize doesn't support batch message, must receive exception at callback.
                Assert.fail();
            }
            return null;
        });
    } finally {
        consumer.close();
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:37,代码来源:ZeroQueueSizeTest.java


示例17: testCleanProducer

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testCleanProducer() throws Exception {
    log.info("-- Starting {} test --", methodName);

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    ProducerConfiguration producerConf = new ProducerConfiguration();
    admin.clusters().createCluster("global", new ClusterData());
    admin.namespaces().createNamespace("my-property/global/lookup");

    ClientConfiguration clientConf = new ClientConfiguration();
    final int operationTimeOut = 500;
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    clientConf.setOperationTimeout(operationTimeOut, TimeUnit.MILLISECONDS);
    PulsarClient pulsarClient = PulsarClient.create(lookupUrl.toString(), clientConf);
    CountDownLatch latch = new CountDownLatch(1);
    pulsarClient.createProducerAsync("persistent://my-property/global/lookup/my-topic1", producerConf)
            .handle((producer, e) -> {
                latch.countDown();
                return null;
            });

    latch.await(operationTimeOut+1000, TimeUnit.MILLISECONDS);
    Field prodField = PulsarClientImpl.class.getDeclaredField("producers");
    prodField.setAccessible(true);
    @SuppressWarnings("unchecked")
    IdentityHashMap<ProducerBase, Boolean> producers = (IdentityHashMap<ProducerBase, Boolean>) prodField
            .get(pulsarClient);
    assertTrue(producers.isEmpty());
    pulsarClient.close();
    log.info("-- Exiting {} test --", methodName);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:33,代码来源:BrokerClientIntegrationTest.java


示例18: testAckTimeoutMinValue

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testAckTimeoutMinValue() throws PulsarClientException {
    ConsumerConfiguration consumerConfig = new ConsumerConfiguration();
    consumerConfig.setReceiverQueueSize(7);
    consumerConfig.setSubscriptionType(SubscriptionType.Failover);
    try {
        consumerConfig.setAckTimeout(999, TimeUnit.MILLISECONDS);
        Assert.fail("Exception should have been thrown since the set timeout is less than min timeout.");
    } catch (Exception ex) {
        // Ok
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:13,代码来源:UnAcknowledgedMessagesTimeoutTest.java


示例19: testConsumerFlowControl

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testConsumerFlowControl() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/topic2";
    final String subName = "sub2";

    Message msg;
    int recvQueueSize = 4;

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    conf.setReceiverQueueSize(recvQueueSize);

    Consumer consumer = pulsarClient.subscribe(topicName, subName, conf);
    Producer producer = pulsarClient.createProducer(topicName);

    PersistentTopic topicRef = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName);
    assertNotNull(topicRef);
    PersistentSubscription subRef = topicRef.getSubscription(subName);
    assertNotNull(subRef);

    // 1. initial receive queue size recorded
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
    assertEquals(getAvailablePermits(subRef), recvQueueSize);

    for (int i = 0; i < recvQueueSize / 2; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
        msg = consumer.receive();
        consumer.acknowledge(msg);
    }

    // 2. queue size re-adjusted after successful receive of half of window size
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
    assertEquals(getAvailablePermits(subRef), recvQueueSize);

    consumer.close();
    assertFalse(subRef.getDispatcher().isConsumerConnected());
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:39,代码来源:PersistentTopicE2ETest.java


示例20: testSimpleCloseTopic

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testSimpleCloseTopic() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/topic5";
    final String subName = "sub5";

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);

    Consumer consumer = pulsarClient.subscribe(topicName, subName, conf);
    Producer producer = pulsarClient.createProducer(topicName);

    PersistentTopic topicRef = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName);
    assertNotNull(topicRef);
    PersistentSubscription subRef = topicRef.getSubscription(subName);
    assertNotNull(subRef);

    Message msg;
    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
        msg = consumer.receive();
        consumer.acknowledge(msg);
    }

    producer.close();
    consumer.close();

    topicRef.close().get();
    assertNull(pulsar.getBrokerService().getTopicReference(topicName));
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:31,代码来源:PersistentTopicE2ETest.java


示例21: testTopicDeleteWithDisconnectedSubscription

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testTopicDeleteWithDisconnectedSubscription() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/topic8";
    final String subName = "sub1";

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);

    // 1. client connect
    Consumer consumer = pulsarClient.subscribe(topicName, subName, conf);

    PersistentTopic topicRef = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName);
    PersistentSubscription subRef = topicRef.getSubscription(subName);

    assertNotNull(topicRef);
    assertNotNull(subRef);
    assertTrue(subRef.getDispatcher().isConsumerConnected());

    // 2. client disconnect
    consumer.close();
    assertFalse(subRef.getDispatcher().isConsumerConnected());

    // 3. delete topic
    admin.persistentTopics().delete(topicName);
    try {
        admin.persistentTopics().getStats(topicName);
    } catch (PulsarAdminException e) {
        // ok
    }
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:31,代码来源:PersistentTopicE2ETest.java


示例22: testGC

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testGC() throws Exception {
    // 1. Simple successful GC
    String topicName = "persistent://prop/use/ns-abc/topic-10";
    Producer producer = pulsarClient.createProducer(topicName);
    producer.close();

    assertNotNull(pulsar.getBrokerService().getTopicReference(topicName));
    runGC();
    assertNull(pulsar.getBrokerService().getTopicReference(topicName));

    // 2. Topic is not GCed with live connection
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    String subName = "sub1";
    Consumer consumer = pulsarClient.subscribe(topicName, subName, conf);

    runGC();
    assertNotNull(pulsar.getBrokerService().getTopicReference(topicName));

    // 3. Topic with subscription is not GCed even with no connections
    consumer.close();

    runGC();
    assertNotNull(pulsar.getBrokerService().getTopicReference(topicName));

    // 4. Topic can be GCed after unsubscribe
    admin.persistentTopics().deleteSubscription(topicName, subName);

    runGC();
    assertNull(pulsar.getBrokerService().getTopicReference(topicName));
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:33,代码来源:PersistentTopicE2ETest.java


示例23: testReceiveWithTimeout

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testReceiveWithTimeout() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/topic-receive-timeout";
    final String subName = "sub";

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    conf.setReceiverQueueSize(1000);

    ConsumerImpl consumer = (ConsumerImpl) pulsarClient.subscribe(topicName, subName, conf);
    Producer producer = pulsarClient.createProducer(topicName);

    assertEquals(consumer.getAvailablePermits(), 0);

    Message msg = consumer.receive(10, TimeUnit.MILLISECONDS);
    assertNull(msg);
    assertEquals(consumer.getAvailablePermits(), 0);

    producer.send("test".getBytes());
    Thread.sleep(100);

    assertEquals(consumer.getAvailablePermits(), 0);

    msg = consumer.receive(10, TimeUnit.MILLISECONDS);
    assertNotNull(msg);
    assertEquals(consumer.getAvailablePermits(), 1);

    msg = consumer.receive(10, TimeUnit.MILLISECONDS);
    assertNull(msg);
    assertEquals(consumer.getAvailablePermits(), 1);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:32,代码来源:PersistentTopicE2ETest.java


示例24: testTopicInternalStats

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testTopicInternalStats() throws Exception {
    log.info("-- Starting {} test --", methodName);

    final String topicName = "persistent://my-property/use/my-ns/my-topic1";
    final String subscriptionName = "my-subscriber-name";
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    Consumer consumer = pulsarClient.subscribe(topicName, subscriptionName, conf);

    ProducerConfiguration producerConf = new ProducerConfiguration();

    Producer producer = pulsarClient.createProducer(topicName, producerConf);
    final int numberOfMsgs = 1000;
    for (int i = 0; i < numberOfMsgs; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }

    Message msg = null;
    int count = 0;
    for (int i = 0; i < numberOfMsgs; i++) {
        msg = consumer.receive(5, TimeUnit.SECONDS);
        if (msg != null && count++ % 2 == 0) {
            consumer.acknowledge(msg);
        }
    }

    PersistentTopic topic = (PersistentTopic) pulsar.getBrokerService().getTopic(topicName).get();
    PersistentTopicInternalStats internalStats = topic.getInternalStats();
    CursorStats cursor = internalStats.cursors.get(subscriptionName);
    assertEquals(cursor.numberOfEntriesSinceFirstNotAckedMessage, numberOfMsgs);
    assertTrue(cursor.totalNonContiguousDeletedMessagesRange > 0
            && (cursor.totalNonContiguousDeletedMessagesRange) < numberOfMsgs / 2);
    
    producer.close();
    consumer.close();
    log.info("-- Exiting {} test --", methodName);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:40,代码来源:PulsarBrokerStatsClientTest.java


示例25: redeliverUnacknowledgedMessages

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Override
public void redeliverUnacknowledgedMessages(Set<MessageIdImpl> messageIds) {
    if (conf.getSubscriptionType() != SubscriptionType.Shared) {
        // We cannot redeliver single messages if subscription type is not Shared
        redeliverUnacknowledgedMessages();
        return;
    }
    removeExpiredMessagesFromQueue(messageIds);
    messageIds.stream()
            .collect(Collectors.groupingBy(MessageIdImpl::getPartitionIndex, Collectors.toSet()))
            .forEach((partitionIndex, messageIds1) ->
                    consumers.get(partitionIndex).redeliverUnacknowledgedMessages(messageIds1));
    resumeReceivingFromPausedConsumersIfNeeded();
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:15,代码来源:PartitionedConsumerImpl.java


示例26: getSubscriptionType

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
public SubscriptionType getSubscriptionType() {
    return SubscriptionType.Exclusive;
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:4,代码来源:ReaderHandler.java


示例27: getSubscriptionType

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
public SubscriptionType getSubscriptionType() {
    return conf.getSubscriptionType();
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:4,代码来源:ConsumerHandler.java


示例28: testSyncProducerAndConsumer

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test(dataProvider = "batch_with_timeout")
public void testSyncProducerAndConsumer(int batchMessageDelayMs, int ackTimeoutSec) throws Exception {
    log.info("-- Starting {} test --", methodName);
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    // Cumulative Ack-counter works if ackTimeOutTimer-task is enabled
    boolean isAckTimeoutTaskEnabledForCumulativeAck = ackTimeoutSec > 0;
    if (ackTimeoutSec > 0) {
        conf.setAckTimeout(ackTimeoutSec, TimeUnit.SECONDS);
    }

    Consumer consumer = pulsarClient.subscribe("persistent://my-property/tp1/my-ns/my-topic1", "my-subscriber-name",
            conf);

    ProducerConfiguration producerConf = new ProducerConfiguration();
    if (batchMessageDelayMs != 0) {
        producerConf.setBatchingEnabled(true);
        producerConf.setBatchingMaxPublishDelay(batchMessageDelayMs, TimeUnit.MILLISECONDS);
        producerConf.setBatchingMaxMessages(5);
    }

    Producer producer = pulsarClient.createProducer("persistent://my-property/tp1/my-ns/my-topic1", producerConf);

    int numMessages = 11;
    for (int i = 0; i < numMessages; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }

    Message msg = null;
    Set<String> messageSet = Sets.newHashSet();
    for (int i = 0; i < numMessages; i++) {
        msg = consumer.receive(5, TimeUnit.SECONDS);
        String receivedMessage = new String(msg.getData());
        log.info("Received message: [{}]", receivedMessage);
        String expectedMessage = "my-message-" + i;
        testMessageOrderAndDuplicates(messageSet, receivedMessage, expectedMessage);
    }
    // Acknowledge the consumption of all messages at once
    consumer.acknowledgeCumulative(msg);
    Thread.sleep(2000);
    consumer.close();
    producer.close();
    validatingLogInfo(consumer, producer, isAckTimeoutTaskEnabledForCumulativeAck);
    log.info("-- Exiting {} test --", methodName);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:47,代码来源:SimpleProducerConsumerStatTest.java


示例29: testSendTimeout

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test(dataProvider = "batch")
public void testSendTimeout(int batchMessageDelayMs) throws Exception {
    log.info("-- Starting {} test --", methodName);

    ConsumerConfiguration consumerConf = new ConsumerConfiguration();
    consumerConf.setSubscriptionType(SubscriptionType.Exclusive);
    Consumer consumer = pulsarClient.subscribe("persistent://my-property/tp1/my-ns/my-topic5", "my-subscriber-name",
            consumerConf);
    ProducerConfiguration producerConf = new ProducerConfiguration();
    if (batchMessageDelayMs != 0) {
        producerConf.setBatchingMaxPublishDelay(2 * batchMessageDelayMs, TimeUnit.MILLISECONDS);
        producerConf.setBatchingMaxMessages(5);
        producerConf.setBatchingEnabled(true);
    }
    producerConf.setSendTimeout(1, TimeUnit.SECONDS);

    Producer producer = pulsarClient.createProducer("persistent://my-property/tp1/my-ns/my-topic5", producerConf);
    final String message = "my-message";

    // Trigger the send timeout
    stopBroker();

    Future<MessageId> future = producer.sendAsync(message.getBytes());

    try {
        future.get();
        fail("Send operation should have failed");
    } catch (ExecutionException e) {
        // Expected
    }

    startBroker();

    // We should not have received any message
    Message msg = consumer.receive(3, TimeUnit.SECONDS);
    assertNull(msg);
    consumer.close();
    producer.close();
    Thread.sleep(1000);
    ConsumerStats cStat = consumer.getStats();
    ProducerStats pStat = producer.getStats();
    assertEquals(pStat.getTotalMsgsSent(), 0);
    assertEquals(pStat.getTotalSendFailed(), 1);
    assertEquals(cStat.getTotalMsgsReceived(), 0);
    assertEquals(cStat.getTotalMsgsReceived(), cStat.getTotalAcksSent());
    log.info("-- Exiting {} test --", methodName);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:48,代码来源:SimpleProducerConsumerStatTest.java


示例30: testRoundRobinProducer

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test(timeOut = 30000)
public void testRoundRobinProducer() throws Exception {
    log.info("-- Starting {} test --", methodName);

    int numPartitions = 4;
    DestinationName dn = DestinationName.get("persistent://my-property/use/my-ns/my-partitionedtopic1");

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);

    admin.persistentTopics().createPartitionedTopic(dn.toString(), numPartitions);

    ProducerConfiguration producerConf = new ProducerConfiguration();
    producerConf.setMessageRoutingMode(MessageRoutingMode.RoundRobinPartition);
    Producer producer = pulsarClient.createProducer(dn.toString(), producerConf);

    Consumer consumer = pulsarClient.subscribe(dn.toString(), "my-partitioned-subscriber", conf);

    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }

    Message msg = null;
    Set<String> messageSet = Sets.newHashSet();
    for (int i = 0; i < 10; i++) {
        msg = consumer.receive(5, TimeUnit.SECONDS);
        Assert.assertNotNull(msg, "Message should not be null");
        consumer.acknowledge(msg);
        String receivedMessage = new String(msg.getData());
        log.debug("Received message: [{}]", receivedMessage);
        Assert.assertTrue(messageSet.add(receivedMessage), "Message " + receivedMessage + " already received");
    }

    producer.close();
    consumer.unsubscribe();
    consumer.close();
    admin.persistentTopics().deletePartitionedTopic(dn.toString());

    log.info("-- Exiting {} test --", methodName);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:42,代码来源:PartitionedProducerConsumerTest.java


示例31: testSinglePartitionProducer

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test(timeOut = 30000)
public void testSinglePartitionProducer() throws Exception {
    log.info("-- Starting {} test --", methodName);

    int numPartitions = 4;
    DestinationName dn = DestinationName.get("persistent://my-property/use/my-ns/my-partitionedtopic2");

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);

    admin.persistentTopics().createPartitionedTopic(dn.toString(), numPartitions);

    ProducerConfiguration producerConf = new ProducerConfiguration();
    producerConf.setMessageRoutingMode(MessageRoutingMode.SinglePartition);
    Producer producer = pulsarClient.createProducer(dn.toString(), producerConf);

    Consumer consumer = pulsarClient.subscribe(dn.toString(), "my-partitioned-subscriber", conf);

    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }

    Message msg = null;
    Set<String> messageSet = Sets.newHashSet();

    for (int i = 0; i < 10; i++) {
        msg = consumer.receive(5, TimeUnit.SECONDS);
        Assert.assertNotNull(msg, "Message should not be null");
        consumer.acknowledge(msg);
        String receivedMessage = new String(msg.getData());
        log.debug("Received message: [{}]", receivedMessage);
        String expectedMessage = "my-message-" + i;
        testMessageOrderAndDuplicates(messageSet, receivedMessage, expectedMessage);
    }

    producer.close();
    consumer.unsubscribe();
    consumer.close();
    admin.persistentTopics().deletePartitionedTopic(dn.toString());

    log.info("-- Exiting {} test --", methodName);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:44,代码来源:PartitionedProducerConsumerTest.java


示例32: testAsyncPartitionedProducerConsumer

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test(timeOut = 30000)
public void testAsyncPartitionedProducerConsumer() throws Exception {
    log.info("-- Starting {} test --", methodName);

    final int totalMsg = 100;
    final Set<String> produceMsgs = Sets.newHashSet();
    final Set<String> consumeMsgs = Sets.newHashSet();

    int numPartitions = 4;
    DestinationName dn = DestinationName.get("persistent://my-property/use/my-ns/my-partitionedtopic1");

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Shared);

    admin.persistentTopics().createPartitionedTopic(dn.toString(), numPartitions);

    ProducerConfiguration producerConf = new ProducerConfiguration();
    producerConf.setMessageRoutingMode(MessageRoutingMode.RoundRobinPartition);
    Producer producer = pulsarClient.createProducer(dn.toString(), producerConf);

    Consumer consumer = pulsarClient.subscribe(dn.toString(), "my-partitioned-subscriber", conf);

    // produce messages
    for (int i = 0; i < totalMsg; i++) {
        String message = "my-message-" + i;
        produceMsgs.add(message);
        producer.send(message.getBytes());
    }

    log.info(" start receiving messages :");

    // receive messages
    CountDownLatch latch = new CountDownLatch(totalMsg);
    receiveAsync(consumer, totalMsg, 0, latch, consumeMsgs, executor);

    latch.await();

    // verify message produced correctly
    assertEquals(produceMsgs.size(), totalMsg);
    // verify produced and consumed messages must be exactly same
    produceMsgs.removeAll(consumeMsgs);
    assertTrue(produceMsgs.isEmpty());

    producer.close();
    consumer.unsubscribe();
    consumer.close();
    admin.persistentTopics().deletePartitionedTopic(dn.toString());

    log.info("-- Exiting {} test --", methodName);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:51,代码来源:PartitionedProducerConsumerTest.java


示例33: subType

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@DataProvider
public Object[][] subType() {
    return new Object[][] { { SubscriptionType.Shared }, { SubscriptionType.Failover } };
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:5,代码来源:BrokerClientIntegrationTest.java


示例34: testSharedSingleAckedPartitionedTopic

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test(timeOut = testTimeout)
public void testSharedSingleAckedPartitionedTopic() throws Exception {
    String key = "testSharedSingleAckedPartitionedTopic";
    final String topicName = "persistent://prop/use/ns-abc/topic-" + key;
    final String subscriptionName = "my-shared-subscription-" + key;
    final String messagePredicate = "my-message-" + key + "-";
    final int totalMessages = 20;
    final int numberOfPartitions = 3;
    admin.properties().createProperty("prop", new PropertyAdmin());
    admin.persistentTopics().createPartitionedTopic(topicName, numberOfPartitions);
    // Special step to create partitioned topic

    // 1. producer connect
    ProducerConfiguration prodConfig = new ProducerConfiguration();
    prodConfig.setMessageRoutingMode(MessageRoutingMode.RoundRobinPartition);
    Producer producer = pulsarClient.createProducer(topicName, prodConfig);

    // 2. Create consumer
    ConsumerConfiguration consumerConfig = new ConsumerConfiguration();
    consumerConfig.setReceiverQueueSize(100);
    consumerConfig.setSubscriptionType(SubscriptionType.Shared);
    consumerConfig.setAckTimeout(ackTimeOutMillis, TimeUnit.MILLISECONDS);
    consumerConfig.setConsumerName("Consumer-1");
    Consumer consumer1 = pulsarClient.subscribe(topicName, subscriptionName, consumerConfig);
    consumerConfig.setConsumerName("Consumer-2");
    Consumer consumer2 = pulsarClient.subscribe(topicName, subscriptionName, consumerConfig);

    // 3. producer publish messages
    for (int i = 0; i < totalMessages; i++) {
        String message = messagePredicate + i;
        MessageId msgId = producer.send(message.getBytes());
        log.info("Message produced: {} -- msgId: {}", message, msgId);
    }

    // 4. Receive messages
    int messageCount1 = receiveAllMessage(consumer1, false /* no-ack */);
    int messageCount2 = receiveAllMessage(consumer2, true /* yes-ack */);
    int ackCount1 = 0;
    int ackCount2 = messageCount2;

    log.info(key + " messageCount1 = " + messageCount1);
    log.info(key + " messageCount2 = " + messageCount2);
    log.info(key + " ackCount1 = " + ackCount1);
    log.info(key + " ackCount2 = " + ackCount2);
    assertEquals(messageCount1 + messageCount2, totalMessages);

    // 5. Check if Messages redelivered again
    // Since receive is a blocking call hoping that timeout will kick in
    Thread.sleep((int) (ackTimeOutMillis * 1.1));
    log.info(key + " Timeout should be triggered now");
    messageCount1 = receiveAllMessage(consumer1, true);
    messageCount2 += receiveAllMessage(consumer2, false);

    ackCount1 = messageCount1;

    log.info(key + " messageCount1 = " + messageCount1);
    log.info(key + " messageCount2 = " + messageCount2);
    log.info(key + " ackCount1 = " + ackCount1);
    log.info(key + " ackCount2 = " + ackCount2);
    assertEquals(messageCount1 + messageCount2, totalMessages);
    assertEquals(ackCount1 + messageCount2, totalMessages);

    Thread.sleep((int) (ackTimeOutMillis * 1.1));

    // Since receive is a blocking call hoping that timeout will kick in
    log.info(key + " Timeout should be triggered again");
    ackCount1 += receiveAllMessage(consumer1, true);
    ackCount2 += receiveAllMessage(consumer2, true);
    log.info(key + " ackCount1 = " + ackCount1);
    log.info(key + " ackCount2 = " + ackCount2);
    assertEquals(ackCount1 + ackCount2, totalMessages);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:73,代码来源:UnAcknowledgedMessagesTimeoutTest.java


示例35: persistentTopicsInvalidCursorReset

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void persistentTopicsInvalidCursorReset() throws Exception {
    admin.namespaces().setRetention("prop-xyz/use/ns1", new RetentionPolicies(10, 10));

    assertEquals(admin.persistentTopics().getList("prop-xyz/use/ns1"), Lists.newArrayList());

    String topicName = "persistent://prop-xyz/use/ns1/invalidcursorreset";
    // Force to create a destination
    publishMessagesOnPersistentTopic(topicName, 0);
    assertEquals(admin.persistentTopics().getList("prop-xyz/use/ns1"), Lists.newArrayList(topicName));

    // create consumer and subscription
    URL pulsarUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
    ClientConfiguration clientConf = new ClientConfiguration();
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    PulsarClient client = PulsarClient.create(pulsarUrl.toString(), clientConf);
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    Consumer consumer = client.subscribe(topicName, "my-sub", conf);

    assertEquals(admin.persistentTopics().getSubscriptions(topicName), Lists.newArrayList("my-sub"));

    publishMessagesOnPersistentTopic(topicName, 10);

    List<Message> messages = admin.persistentTopics().peekMessages(topicName, "my-sub", 10);
    assertEquals(messages.size(), 10);

    for (int i = 0; i < 10; i++) {
        Message message = consumer.receive();
        consumer.acknowledge(message);
    }
    // use invalid timestamp
    try {
        admin.persistentTopics().resetCursor(topicName, "my-sub", System.currentTimeMillis() - 190000);
    } catch (Exception e) {
        // fail the test
        throw e;
    }

    admin.persistentTopics().resetCursor(topicName, "my-sub", System.currentTimeMillis() + 90000);
    consumer = client.subscribe(topicName, "my-sub", conf);
    consumer.close();
    client.close();

    admin.persistentTopics().deleteSubscription(topicName, "my-sub");

    assertEquals(admin.persistentTopics().getSubscriptions(topicName), Lists.newArrayList());
    admin.persistentTopics().delete(topicName);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:50,代码来源:AdminApiTest.java


示例36: testPersistentTopicsExpireMessages

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
/**
 * <pre>
 * Verify: PersistentTopics.expireMessages()/expireMessagesForAllSubscriptions()
 * 1. Created multiple shared subscriptions and publisher on topic
 * 2. Publish messages on the topic
 * 3. expire message on sub-1 : backlog for sub-1 must be 0
 * 4. expire message on all subscriptions: backlog for all subscription must be 0
 * </pre>
 * @throws Exception
 */
@Test
public void testPersistentTopicsExpireMessages() throws Exception {

    // Force to create a destination
    publishMessagesOnPersistentTopic("persistent://prop-xyz/use/ns1/ds2", 0);
    assertEquals(admin.persistentTopics().getList("prop-xyz/use/ns1"),
            Lists.newArrayList("persistent://prop-xyz/use/ns1/ds2"));

    // create consumer and subscription
    URL pulsarUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
    ClientConfiguration clientConf = new ClientConfiguration();
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    PulsarClient client = PulsarClient.create(pulsarUrl.toString(), clientConf);
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Shared);
    Consumer consumer1 = client.subscribe("persistent://prop-xyz/use/ns1/ds2", "my-sub1", conf);
    Consumer consumer2 = client.subscribe("persistent://prop-xyz/use/ns1/ds2", "my-sub2", conf);
    Consumer consumer3 = client.subscribe("persistent://prop-xyz/use/ns1/ds2", "my-sub3", conf);

    assertEquals(admin.persistentTopics().getSubscriptions("persistent://prop-xyz/use/ns1/ds2").size(), 3);

    publishMessagesOnPersistentTopic("persistent://prop-xyz/use/ns1/ds2", 10);

    PersistentTopicStats topicStats = admin.persistentTopics().getStats("persistent://prop-xyz/use/ns1/ds2");
    assertEquals(topicStats.subscriptions.get("my-sub1").msgBacklog, 10);
    assertEquals(topicStats.subscriptions.get("my-sub2").msgBacklog, 10);
    assertEquals(topicStats.subscriptions.get("my-sub3").msgBacklog, 10);

    Thread.sleep(1000); // wait for 1 seconds to expire message
    admin.persistentTopics().expireMessages("persistent://prop-xyz/use/ns1/ds2", "my-sub1", 1);
    Thread.sleep(1000); // wait for 1 seconds to execute expire message as it is async

    topicStats = admin.persistentTopics().getStats("persistent://prop-xyz/use/ns1/ds2");
    assertEquals(topicStats.subscriptions.get("my-sub1").msgBacklog, 0);
    assertEquals(topicStats.subscriptions.get("my-sub2").msgBacklog, 10);
    assertEquals(topicStats.subscriptions.get("my-sub3").msgBacklog, 10);

    admin.persistentTopics().expireMessagesForAllSubscriptions("persistent://prop-xyz/use/ns1/ds2", 1);
    Thread.sleep(1000); // wait for 1 seconds to execute expire message as it is async

    topicStats = admin.persistentTopics().getStats("persistent://prop-xyz/use/ns1/ds2");
    assertEquals(topicStats.subscriptions.get("my-sub1").msgBacklog, 0);
    assertEquals(topicStats.subscriptions.get("my-sub2").msgBacklog, 0);
    assertEquals(topicStats.subscriptions.get("my-sub3").msgBacklog, 0);

    consumer1.close();
    consumer2.close();
    consumer3.close();

}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:61,代码来源:AdminApiTest.java


示例37: testPersistentTopicExpireMessageOnParitionTopic

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
/**
 * Verify: PersistentTopics.expireMessages()/expireMessagesForAllSubscriptions() for PartitionTopic
 *
 * @throws Exception
 */
@Test
public void testPersistentTopicExpireMessageOnParitionTopic() throws Exception {

    admin.persistentTopics().createPartitionedTopic("persistent://prop-xyz/use/ns1/ds1", 4);

    // create consumer and subscription
    URL pulsarUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
    ClientConfiguration clientConf = new ClientConfiguration();
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    PulsarClient client = PulsarClient.create(pulsarUrl.toString(), clientConf);
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    Consumer consumer = client.subscribe("persistent://prop-xyz/use/ns1/ds1", "my-sub", conf);

    ProducerConfiguration prodConf = new ProducerConfiguration();
    prodConf.setMessageRoutingMode(MessageRoutingMode.RoundRobinPartition);
    Producer producer = client.createProducer("persistent://prop-xyz/use/ns1/ds1", prodConf);
    for (int i = 0; i < 10; i++) {
        String message = "message-" + i;
        producer.send(message.getBytes());
    }

    PartitionedTopicStats topicStats = admin.persistentTopics()
            .getPartitionedStats("persistent://prop-xyz/use/ns1/ds1", true);
    assertEquals(topicStats.subscriptions.get("my-sub").msgBacklog, 10);

    PersistentTopicStats partitionStatsPartition0 = topicStats.partitions
            .get("persistent://prop-xyz/use/ns1/ds1-partition-0");
    PersistentTopicStats partitionStatsPartition1 = topicStats.partitions
            .get("persistent://prop-xyz/use/ns1/ds1-partition-1");
    assertEquals(partitionStatsPartition0.subscriptions.get("my-sub").msgBacklog, 3, 1);
    assertEquals(partitionStatsPartition1.subscriptions.get("my-sub").msgBacklog, 3, 1);

    Thread.sleep(1000);
    admin.persistentTopics().expireMessagesForAllSubscriptions("persistent://prop-xyz/use/ns1/ds1", 1);
    Thread.sleep(1000);

    topicStats = admin.persistentTopics().getPartitionedStats("persistent://prop-xyz/use/ns1/ds1", true);
    partitionStatsPartition0 = topicStats.partitions.get("persistent://prop-xyz/use/ns1/ds1-partition-0");
    partitionStatsPartition1 = topicStats.partitions.get("persistent://prop-xyz/use/ns1/ds1-partition-1");
    assertEquals(partitionStatsPartition0.subscriptions.get("my-sub").msgBacklog, 0);
    assertEquals(partitionStatsPartition1.subscriptions.get("my-sub").msgBacklog, 0);

    producer.close();
    consumer.close();
    client.close();

}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:54,代码来源:AdminApiTest.java


示例38: nonPersistentTopics

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
/**
 * verifies admin api command for non-persistent topic.
 * It verifies: partitioned-topic, stats
 * @throws Exception
 */
@Test
public void nonPersistentTopics() throws Exception {
    final String topicName = "nonPersistentTopic";

    final String persistentTopicName = "non-persistent://prop-xyz/use/ns1/" + topicName;
    // Force to create a destination
    publishMessagesOnTopic("non-persistent://prop-xyz/use/ns1/" + topicName, 0, 0);

    // create consumer and subscription
    URL pulsarUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
    ClientConfiguration clientConf = new ClientConfiguration();
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    PulsarClient client = PulsarClient.create(pulsarUrl.toString(), clientConf);
    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    Consumer consumer = client.subscribe(persistentTopicName, "my-sub", conf);

    publishMessagesOnTopic("non-persistent://prop-xyz/use/ns1/" + topicName, 10, 0);

    NonPersistentTopicStats topicStats = admin.nonPersistentTopics().getStats(persistentTopicName);
    assertEquals(topicStats.getSubscriptions().keySet(), Sets.newTreeSet(Lists.newArrayList("my-sub")));
    assertEquals(topicStats.getSubscriptions().get("my-sub").consumers.size(), 1);
    assertEquals(topicStats.getPublishers().size(), 0);

    PersistentTopicInternalStats internalStats = admin.nonPersistentTopics().getInternalStats(persistentTopicName);
    assertEquals(internalStats.cursors.keySet(), Sets.newTreeSet(Lists.newArrayList("my-sub")));

    consumer.close();
    client.close();

    topicStats = admin.nonPersistentTopics().getStats(persistentTopicName);
    assertTrue(topicStats.getSubscriptions().keySet().contains("my-sub"));
    assertEquals(topicStats.getPublishers().size(), 0);

    // test partitioned-topic
    final String partitionedTopicName = "non-persistent://prop-xyz/use/ns1/paritioned";
    assertEquals(admin.nonPersistentTopics().getPartitionedTopicMetadata(partitionedTopicName).partitions, 0);
    admin.nonPersistentTopics().createPartitionedTopic(partitionedTopicName, 5);
    assertEquals(admin.nonPersistentTopics().getPartitionedTopicMetadata(partitionedTopicName).partitions, 5);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:46,代码来源:AdminApiTest2.java


示例39: testBrokerServicePersistentTopicStats

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testBrokerServicePersistentTopicStats() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/successTopic";
    final String subName = "successSub";

    PersistentTopicStats stats;
    SubscriptionStats subStats;

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    Consumer consumer = pulsarClient.subscribe(topicName, subName, conf);
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);

    PersistentTopic topicRef = (PersistentTopic) pulsar.getBrokerService().getTopicReference(topicName);
    assertNotNull(topicRef);

    rolloverPerIntervalStats();
    stats = topicRef.getStats();
    subStats = stats.subscriptions.values().iterator().next();

    // subscription stats
    assertEquals(stats.subscriptions.keySet().size(), 1);
    assertEquals(subStats.msgBacklog, 0);
    assertEquals(subStats.consumers.size(), 1);

    Producer producer = pulsarClient.createProducer(topicName);
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);

    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);

    rolloverPerIntervalStats();
    stats = topicRef.getStats();
    subStats = stats.subscriptions.values().iterator().next();

    // publisher stats
    assertEquals(subStats.msgBacklog, 10);
    assertEquals(stats.publishers.size(), 1);
    assertTrue(stats.publishers.get(0).msgRateIn > 0.0);
    assertTrue(stats.publishers.get(0).msgThroughputIn > 0.0);
    assertTrue(stats.publishers.get(0).averageMsgSize > 0.0);
    assertNotNull(stats.publishers.get(0).clientVersion);

    // aggregated publish stats
    assertEquals(stats.msgRateIn, stats.publishers.get(0).msgRateIn);
    assertEquals(stats.msgThroughputIn, stats.publishers.get(0).msgThroughputIn);
    double diff = stats.averageMsgSize - stats.publishers.get(0).averageMsgSize;
    assertTrue(Math.abs(diff) < 0.000001);

    // consumer stats
    assertTrue(subStats.consumers.get(0).msgRateOut > 0.0);
    assertTrue(subStats.consumers.get(0).msgThroughputOut > 0.0);

    // aggregated consumer stats
    assertEquals(subStats.msgRateOut, subStats.consumers.get(0).msgRateOut);
    assertEquals(subStats.msgThroughputOut, subStats.consumers.get(0).msgThroughputOut);
    assertEquals(stats.msgRateOut, subStats.consumers.get(0).msgRateOut);
    assertEquals(stats.msgThroughputOut, subStats.consumers.get(0).msgThroughputOut);
    assertNotNull(subStats.consumers.get(0).clientVersion);

    Message msg;
    for (int i = 0; i < 10; i++) {
        msg = consumer.receive();
        consumer.acknowledge(msg);
    }
    consumer.close();
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);

    rolloverPerIntervalStats();
    stats = topicRef.getStats();
    subStats = stats.subscriptions.values().iterator().next();

    assertEquals(subStats.msgBacklog, 0);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:78,代码来源:BrokerServiceTest.java


示例40: testBrokerStatsMetrics

import org.apache.pulsar.client.api.SubscriptionType; //导入依赖的package包/类
@Test
public void testBrokerStatsMetrics() throws Exception {
    final String topicName = "persistent://prop/use/ns-abc/newTopic";
    final String subName = "newSub";
    BrokerStats brokerStatsClient = admin.brokerStats();

    ConsumerConfiguration conf = new ConsumerConfiguration();
    conf.setSubscriptionType(SubscriptionType.Exclusive);
    Consumer consumer = pulsarClient.subscribe(topicName, subName, conf);
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);

    Producer producer = pulsarClient.createProducer(topicName);
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);

    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
    Message msg = null;
    for (int i = 0; i < 10; i++) {
        msg = consumer.receive();
        consumer.acknowledge(msg);
    }
    consumer.close();
    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
    JsonArray metrics = brokerStatsClient.getMetrics();
    assertEquals(metrics.size(), 5, metrics.toString());

    // these metrics seem to be arriving in different order at different times...
    // is the order really relevant here?
    boolean namespaceDimensionFound = false;
    boolean topicLoadTimesDimensionFound = false;
    for ( int i=0; i<metrics.size(); i++ ) {
        try {
            String data = metrics.get(i).getAsJsonObject().get("dimensions").toString();
            if (!namespaceDimensionFound && data.contains("prop/use/ns-abc")) {
                namespaceDimensionFound = true;
            }
            if (!topicLoadTimesDimensionFound && data.contains("prop/use/ns-abc")) {
                topicLoadTimesDimensionFound = true;
            }
        } catch (Exception e) { /* it's possible there's no dimensions */ }
    }

    assertTrue(namespaceDimensionFound && topicLoadTimesDimensionFound);

    Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:50,代码来源:BrokerServiceTest.java



注:本文中的org.apache.pulsar.client.api.SubscriptionType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。