Package com.netflix.suro.client

Examples of com.netflix.suro.client.SuroClient


            final Properties clientProperties = new Properties();
            clientProperties.setProperty(ClientConfig.LB_TYPE, "static");
            clientProperties.setProperty(ClientConfig.LB_SERVER, "localhost:" + suroServer.getServerPort());
            clientProperties.setProperty(ClientConfig.CLIENT_TYPE, "sync");

            SuroClient client = new SuroClient(clientProperties);

            for (int i = 0; i < 10; ++i) {
                client.send(new Message("topic1", Integer.toString(i).getBytes()));
            }
            for (int i = 0; i < 5; ++i) {
                client.send(new Message("topic2", Integer.toString(i).getBytes()));
            }
            for (int i = 0; i < 20; ++i) {
                client.send(new Message("topic3", Integer.toString(i).getBytes()));
            }

            for(int i = 0; i < 30; ++i) {
                Map<String, Object> message = makeMessage("foo/bar", "value"+i);
                client.send(new Message("topic4", jsonMapper.writeValueAsBytes(message)));
            }

            int count = 10;
            while (!answer() && count > 0) {
                Thread.sleep(1000);
                --count;
            }

            assertTrue(answer());
            client.shutdown();
           
        } catch (Exception e) {
            System.err.println("SuroServer startup failed: " + e.getMessage());
            System.exit(-1);
        }
View Full Code Here


        final Properties clientProperties = new Properties();
        clientProperties.setProperty(ClientConfig.LB_TYPE, "static");
        clientProperties.setProperty(ClientConfig.LB_SERVER, args[0]);
        clientProperties.setProperty(ClientConfig.CLIENT_TYPE, args[1]);

        SuroClient client = new SuroClient(clientProperties);

        // send the message
        for (int i = 0; i < Integer.parseInt(args[2]); ++i) {
            client.send(new Message("routingKey", "testMessage".getBytes()));
        }

        client.shutdown();
    }
View Full Code Here

        Properties props = new Properties();
        props.setProperty(ClientConfig.LB_TYPE, "static");
        props.setProperty(ClientConfig.LB_SERVER, ip);

        SuroClient client = new SuroClient(props);
        byte[] payload = createMessagePayload(messageSize);
        for (int n = 0; n < numIterations; ++n) {
            for (int i = 0; i < numMessages; ++i) {
                client.send(new Message(i % 2 == 0 ? "request_trace" : "nf_errors_log", payload));
            }
            Thread.sleep(sleep);
        }
        client.shutdown();
    }
View Full Code Here

    @VisibleForTesting
    protected SuroClient client;

    @Override
    public void activateOptions() {
        client = new SuroClient(createProperties());

        try {
            formatter = (Log4jFormatter)
                    Class.forName(formatterClass).getDeclaredConstructor(ClientConfig.class)
                            .newInstance(client.getConfig());
View Full Code Here

        client.send(message.getMessage());
    }

    @Override
    public void open() {
        client = new SuroClient(props);
    }
View Full Code Here

        final Properties clientProperties = new Properties();
        clientProperties.setProperty(ClientConfig.LB_TYPE, "static");
        clientProperties.setProperty(ClientConfig.LB_SERVER, "localhost:" + suroServer.getServerPort());
        clientProperties.setProperty(ClientConfig.CLIENT_TYPE, "sync");

        SuroClient client = new SuroClient(clientProperties);

        // send the message
        client.send(new Message("routingKey", "testMessage".getBytes()));

        // check the test server whether it got received
        TestMessageRouter.TestMessageRouterSink testSink = (TestMessageRouter.TestMessageRouterSink)
                suroServer.getInjector().getInstance(SinkManager.class).getSink("default");
        assertEquals(testSink.getMessageList().size(), 1);
        assertEquals(testSink.getMessageList().get(0), "testMessage");

        client.shutdown();
    }
View Full Code Here

        final Properties clientProperties = new Properties();
        clientProperties.setProperty(ClientConfig.LB_TYPE, "static");
        clientProperties.setProperty(ClientConfig.LB_SERVER, "localhost:" + suroServer.getServerPort());
        clientProperties.setProperty(ClientConfig.ASYNC_TIMEOUT, "0");

        SuroClient client = new SuroClient(clientProperties);

        final int numMessages = 2;
        final int waitTime = 10;

        for (int i = 0; i < numMessages; ++i) {
            client.send(new Message("routingKey", "testMessage".getBytes()));
        }

        // check the test server whether it got received
        TestMessageRouter.TestMessageRouterSink testSink = (TestMessageRouter.TestMessageRouterSink)
                suroServer.getInjector().getInstance(SinkManager.class).getSink("default");

        int count = 0;
        while (client.getSentMessageCount() < numMessages && count < waitTime) {
            Thread.sleep(1000);
            ++count;
        }
        assertEquals(client.getSentMessageCount(), numMessages);
        count = 0;
        while (testSink.getMessageList().size() < numMessages && count < waitTime) {
            Thread.sleep(1000);
            ++count;
        }
View Full Code Here

        );

        ThriftServer server = new ThriftServer(config, msgProcessor);
        server.start();

        SuroClient client = createSuroClient(server.getPort());

        Thread t = createClientThread(jsonMapper, client, TOPIC_NAME);

        // checking the traffic goes
        for (int i = 0; i < 10; ++i) {
            if (client.getSentMessageCount() > 0) {
                break;
            }
            Thread.sleep(1000);
        }
        assertTrue(client.getSentMessageCount() > 0);

        // shutting down the traffic
        hasEnoughSpace = false;
        int count = 0;
        while (count < 3) {
            if (msgProcessor.getStatus() == ServiceStatus.WARNING) {
                ++count;
            }
        }
        assertEquals(count, 3);

        client.shutdown();
        run.set(false);
        t.join();

        // resuming the traffic
        hasEnoughSpace = true;
        run.set(true);
        SuroClient newClient = createSuroClient(server.getPort());
        t = createClientThread(jsonMapper, newClient, TOPIC_NAME);

        for (int i = 0; i < 10; ++i) {
            if (client.getSentMessageCount() > 0) {
                break;
View Full Code Here

        clientProperties.setProperty(ClientConfig.LB_TYPE, "static");
        clientProperties.setProperty(ClientConfig.LB_SERVER, "localhost:" + port);
        clientProperties.setProperty(ClientConfig.ASYNC_TIMEOUT, "0");
        clientProperties.setProperty(ClientConfig.ENABLE_OUTPOOL, "true");

        return new SuroClient(clientProperties);
    }
View Full Code Here

TOP

Related Classes of com.netflix.suro.client.SuroClient

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.