Package org.apache.hedwig.client.api

Examples of org.apache.hedwig.client.api.Publisher


    @Test(timeout=60000)
    public void testMultipleSubscribers() throws Exception {
        ByteString topic = ByteString.copyFromUtf8("multiSubTopic");

        Client client = new HedwigClient(new HubClientConfiguration());
        Publisher pub = client.getPublisher();
        Subscriber sub = client.getSubscriber();

        SubscriptionOptions options5 = SubscriptionOptions.newBuilder()
            .setCreateOrAttach(CreateOrAttach.CREATE).setMessageBound(5).build();
        SubscriptionOptions options20 = SubscriptionOptions.newBuilder()
View Full Code Here


    @Test(timeout=60000)
    public void testUpdateMessageBound() throws Exception {
        ByteString topic = ByteString.copyFromUtf8("UpdateMessageBound");

        Client client = new HedwigClient(new HubClientConfiguration());
        Publisher pub = client.getPublisher();
        Subscriber sub = client.getSubscriber();

        SubscriptionOptions options5 = SubscriptionOptions.newBuilder()
            .setCreateOrAttach(CreateOrAttach.CREATE_OR_ATTACH).setMessageBound(5).build();
        SubscriptionOptions options20 = SubscriptionOptions.newBuilder()
View Full Code Here

    }

    @Test(timeout=60000)
    public void testLedgerGC() throws Exception {
        Client client = new HedwigClient(new MessageBoundClientConfiguration());
        Publisher pub = client.getPublisher();
        Subscriber sub = client.getSubscriber();

        String ledgersPath = "/hedwig/standalone/topics/testGCTopic/ledgers";
        ByteString topic = ByteString.copyFromUtf8("testGCTopic");
        ByteString subid = ByteString.copyFromUtf8("testGCSubId");
        sub.subscribe(topic, subid, CreateOrAttach.CREATE_OR_ATTACH);
        sub.closeSubscription(topic, subid);

        for (int i = 1; i <= 100; i++) {
            pub.publish(topic, Message.newBuilder().setBody(
                                ByteString.copyFromUtf8(String.valueOf(i))).build());
        }
        LedgerRanges r = LedgerRanges.parseFrom(bktb.getZooKeeperClient().getData(ledgersPath, false, null));
        assertEquals("Should only have 1 ledger yet", 1, r.getRangesList().size());
        long firstLedger = r.getRangesList().get(0).getLedgerId();

        stopHubServers();
        startHubServers();

        pub.publish(topic, Message.newBuilder().setBody(
                            ByteString.copyFromUtf8(String.valueOf(0xdeadbeef))).build());

        r = LedgerRanges.parseFrom(bktb.getZooKeeperClient().getData(ledgersPath, false, null));
        assertEquals("Should have 2 ledgers after restart", 2, r.getRangesList().size());

        for (int i = 100; i <= 200; i++) {
            pub.publish(topic, Message.newBuilder().setBody(
                                ByteString.copyFromUtf8(String.valueOf(i))).build());
        }
        Thread.sleep(5000); // give GC a chance to happen

        r = LedgerRanges.parseFrom(bktb.getZooKeeperClient().getData(ledgersPath, false, null));
View Full Code Here

        }

        // Now start publishing messages for the subscribed topics in one of the
        // regions and verify that it gets delivered and consumed in all of the
        // other ones.
        Publisher publisher = regionClientsMap.values().iterator().next().getPublisher();
        for (int i = 0; i < batchSize; i++) {
            publisher.asyncPublish(ByteString.copyFromUtf8("Topic" + i), Message.newBuilder().setBody(
                                       ByteString.copyFromUtf8("Message" + i)).build(), new TestCallback(queue), null);
            assertTrue(queue.take());
        }
        // Make sure each region consumes the same set of published messages.
        for (int i = 0; i < regionClientsMap.size(); i++) {
View Full Code Here

        // Now start publishing messages for the subscribed topics in one of the
        // regions and verify that it gets delivered and consumed in all of the
        // other ones.
        int rid = r.nextInt(numRegions);
        String regionName = REGION_PREFIX + rid;
        Publisher publisher = regionClientsMap.get(regionName).getPublisher();
        for (int i = 0; i < batchSize; i++) {
            publisher.asyncPublish(ByteString.copyFromUtf8("Topic" + i), Message.newBuilder().setBody(
                                   ByteString.copyFromUtf8(regionName + "-Message" + i)).build(), new TestCallback(queue), null);
            assertTrue(queue.take());
        }
        // Make sure each region consumes the same set of published messages.
        for (int i = 0; i < regionClientsMap.size(); i++) {
View Full Code Here

        }

        // Now start publishing messages for the subscribed topics in one of the
        // regions and verify that it gets delivered and consumed in all of the
        // other ones.       
        Publisher publisher = client.getPublisher();
        for (int i = 0; i < batchSize; i++) {
            publisher.asyncPublish(ByteString.copyFromUtf8("Topic" + i), Message.newBuilder().setBody(
                                   ByteString.copyFromUtf8(regionName + "-Message" + i)).build(), new TestCallback(queue), null);
            assertTrue(queue.take());
        }
        // Make sure each region consumes the same set of published messages.
        for (int i = 0; i < regionClientsMap.size(); i++) {
View Full Code Here

TOP

Related Classes of org.apache.hedwig.client.api.Publisher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.