Search in sources :

Example 11 with ClientConfiguration

use of org.apache.pulsar.client.api.ClientConfiguration in project incubator-pulsar by apache.

the class PulsarBoltTest method testSerializability.

@Test
public void testSerializability() throws Exception {
    // test serializability with no auth
    PulsarBolt boltWithNoAuth = new PulsarBolt(pulsarBoltConf, new ClientConfiguration());
    TestUtil.testSerializability(boltWithNoAuth);
}
Also used : ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Example 12 with ClientConfiguration

use of org.apache.pulsar.client.api.ClientConfiguration in project incubator-pulsar by apache.

the class PulsarSpoutTest method setup.

@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);
}
Also used : PulsarSpoutConfiguration(org.apache.pulsar.storm.PulsarSpoutConfiguration) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) ConsumerConfiguration(org.apache.pulsar.client.api.ConsumerConfiguration) TopologyContext(org.apache.storm.task.TopologyContext) PulsarSpout(org.apache.pulsar.storm.PulsarSpout) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration)

Example 13 with ClientConfiguration

use of org.apache.pulsar.client.api.ClientConfiguration in project incubator-pulsar by apache.

the class PulsarSpoutTest method testFailedConsumer.

@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
    }
}
Also used : PulsarSpoutConfiguration(org.apache.pulsar.storm.PulsarSpoutConfiguration) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) ConsumerConfiguration(org.apache.pulsar.client.api.ConsumerConfiguration) TopologyContext(org.apache.storm.task.TopologyContext) PulsarSpout(org.apache.pulsar.storm.PulsarSpout) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Example 14 with ClientConfiguration

use of org.apache.pulsar.client.api.ClientConfiguration in project incubator-pulsar by apache.

the class StormExample method main.

public static void main(String[] args) throws PulsarClientException {
    ClientConfiguration clientConf = new ClientConfiguration();
    // String authPluginClassName = "org.apache.pulsar.client.impl.auth.MyAuthentication";
    // String authParams = "key1:val1,key2:val2";
    // clientConf.setAuthentication(authPluginClassName, authParams);
    String topic1 = "persistent://my-property/use/my-ns/my-topic1";
    String topic2 = "persistent://my-property/use/my-ns/my-topic2";
    String subscriptionName1 = "my-subscriber-name1";
    String subscriptionName2 = "my-subscriber-name2";
    // create spout
    PulsarSpoutConfiguration spoutConf = new PulsarSpoutConfiguration();
    spoutConf.setServiceUrl(serviceUrl);
    spoutConf.setTopic(topic1);
    spoutConf.setSubscriptionName(subscriptionName1);
    spoutConf.setMessageToValuesMapper(messageToValuesMapper);
    PulsarSpout spout = new PulsarSpout(spoutConf, clientConf);
    // create bolt
    PulsarBoltConfiguration boltConf = new PulsarBoltConfiguration();
    boltConf.setServiceUrl(serviceUrl);
    boltConf.setTopic(topic2);
    boltConf.setTupleToMessageMapper(tupleToMessageMapper);
    PulsarBolt bolt = new PulsarBolt(boltConf, clientConf);
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("testSpout", spout);
    builder.setBolt("testBolt", bolt).shuffleGrouping("testSpout");
    Config conf = new Config();
    conf.setNumWorkers(2);
    conf.setDebug(true);
    conf.registerMetricsConsumer(PulsarMetricsConsumer.class);
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("test", conf, builder.createTopology());
    Utils.sleep(10000);
    PulsarClient pulsarClient = PulsarClient.create(serviceUrl, clientConf);
    // create a consumer on topic2 to receive messages from the bolt when the processing is done
    Consumer consumer = pulsarClient.subscribe(topic2, subscriptionName2);
    // create a producer on topic1 to send messages that will be received by the spout
    Producer producer = pulsarClient.createProducer(topic1);
    for (int i = 0; i < 10; i++) {
        String msg = "msg-" + i;
        producer.send(msg.getBytes());
        LOG.info("Message {} sent", msg);
    }
    Message msg = null;
    for (int i = 0; i < 10; i++) {
        msg = consumer.receive(1, TimeUnit.SECONDS);
        LOG.info("Message {} received", new String(msg.getData()));
    }
    cluster.killTopology("test");
    cluster.shutdown();
}
Also used : LocalCluster(org.apache.storm.LocalCluster) PulsarBolt(org.apache.pulsar.storm.PulsarBolt) Message(org.apache.pulsar.client.api.Message) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) PulsarBoltConfiguration(org.apache.pulsar.storm.PulsarBoltConfiguration) PulsarSpout(org.apache.pulsar.storm.PulsarSpout) PulsarSpoutConfiguration(org.apache.pulsar.storm.PulsarSpoutConfiguration) IMetricsConsumer(org.apache.storm.metric.api.IMetricsConsumer) Consumer(org.apache.pulsar.client.api.Consumer) Producer(org.apache.pulsar.client.api.Producer) PulsarClient(org.apache.pulsar.client.api.PulsarClient) ClientConfiguration(org.apache.pulsar.client.api.ClientConfiguration)

Aggregations

ClientConfiguration (org.apache.pulsar.client.api.ClientConfiguration)14 TopologyContext (org.apache.storm.task.TopologyContext)7 Test (org.testng.annotations.Test)7 PulsarSpout (org.apache.pulsar.storm.PulsarSpout)6 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)4 ConsumerConfiguration (org.apache.pulsar.client.api.ConsumerConfiguration)3 PersistentTopicStats (org.apache.pulsar.common.policies.data.PersistentTopicStats)3 PulsarSpoutConfiguration (org.apache.pulsar.storm.PulsarSpoutConfiguration)3 OutputCollector (org.apache.storm.task.OutputCollector)3 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)2 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)2 PulsarClient (org.apache.pulsar.client.api.PulsarClient)2 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)2 JCommander (com.beust.jcommander.JCommander)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1