Search in sources :

Example 1 with FluencyBuilderForFluentd

use of org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd in project fluency by komamitsu.

the class WithRealFluentd method testWithRealFluentd.

@Test
void testWithRealFluentd() throws Exception {
    WithRealFluentd.Config config = getConfig();
    assumeTrue(config != null);
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(config.sslEnabled);
    try (Fluency fluency = builder.build(config.host, config.port)) {
        Map<String, Object> data = new HashMap<>();
        data.put("name", "komamitsu");
        data.put("age", 42);
        data.put("comment", "hello, world");
        ExecutorService executorService = Executors.newCachedThreadPool();
        List<Future<Void>> futures = new ArrayList<>();
        for (int i = 0; i < config.concurrency; i++) {
            futures.add(executorService.submit(new EmitTask(fluency, config.tag, data, config.requests)));
        }
        for (Future<Void> future : futures) {
            future.get(config.waitSeconds, TimeUnit.SECONDS);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fluency(org.komamitsu.fluency.Fluency) FluencyBuilderForFluentd(org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Example 2 with FluencyBuilderForFluentd

use of org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd in project fluency by komamitsu.

the class WithRealFluentd method testWithRealMultipleFluentd.

@Test
void testWithRealMultipleFluentd() throws IOException, InterruptedException, TimeoutException, ExecutionException {
    WithRealFluentd.Config config = getConfig();
    assumeTrue(config != null);
    assumeTrue(config.anotherPort != null);
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(config.sslEnabled);
    builder.setAckResponseMode(true);
    try (Fluency fluency = builder.build(Arrays.asList(new InetSocketAddress(config.host, config.port), new InetSocketAddress(config.host, config.anotherPort)))) {
        Map<String, Object> data = new HashMap<>();
        data.put("name", "komamitsu");
        data.put("age", 42);
        data.put("comment", "hello, world");
        ExecutorService executorService = Executors.newCachedThreadPool();
        List<Future<Void>> futures = new ArrayList<>();
        for (int i = 0; i < config.concurrency; i++) {
            futures.add(executorService.submit(new EmitTask(fluency, config.tag, data, config.requests)));
        }
        for (Future<Void> future : futures) {
            future.get(config.waitSeconds, TimeUnit.SECONDS);
        }
    }
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) Fluency(org.komamitsu.fluency.Fluency) FluencyBuilderForFluentd(org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Example 3 with FluencyBuilderForFluentd

use of org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd in project fluency by komamitsu.

the class Main method main.

public static void main(String[] args) throws IOException {
    String host = args[0];
    int port = Integer.parseInt(args[1]);
    String tag = args[2];
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(true);
    builder.setWaitUntilBufferFlushed(5000);
    builder.setWaitUntilFlusherTerminated(5000);
    builder.setSenderMaxRetryCount(4);
    Fluency fluency = builder.build(host, port);
    Map<String, Object> event = new HashMap<>();
    event.put("name", "komamitsu");
    event.put("comment", "zzz");
    fluency.emit(tag, event);
    fluency.close();
}
Also used : Fluency(org.komamitsu.fluency.Fluency) HashMap(java.util.HashMap) FluencyBuilderForFluentd(org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd)

Example 4 with FluencyBuilderForFluentd

use of org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd in project fluency by komamitsu.

the class WithRealFluentd method testWithRealFluentdWithFileBackup.

@Test
void testWithRealFluentdWithFileBackup() throws ExecutionException, TimeoutException, IOException, InterruptedException {
    WithRealFluentd.Config config = getConfig();
    assumeTrue(config != null);
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(config.sslEnabled);
    // Fluency might use a lot of buffer for loaded backup files.
    // So it'd better increase max buffer size
    builder.setMaxBufferSize(512 * 1024 * 1024L);
    builder.setFileBackupDir(System.getProperty("java.io.tmpdir"));
    try (Fluency fluency = new FluencyBuilderForFluentd().build(config.host, config.port)) {
        Map<String, Object> data = new HashMap<>();
        data.put("name", "komamitsu");
        data.put("age", 42);
        data.put("comment", "hello, world");
        ExecutorService executorService = Executors.newCachedThreadPool();
        List<Future<Void>> futures = new ArrayList<>();
        for (int i = 0; i < config.concurrency; i++) {
            futures.add(executorService.submit(new EmitTask(fluency, config.tag, data, config.requests)));
        }
        for (Future<Void> future : futures) {
            future.get(config.waitSeconds, TimeUnit.SECONDS);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fluency(org.komamitsu.fluency.Fluency) FluencyBuilderForFluentd(org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)4 Fluency (org.komamitsu.fluency.Fluency)4 FluencyBuilderForFluentd (org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd)4 ArrayList (java.util.ArrayList)3 ExecutorService (java.util.concurrent.ExecutorService)3 Future (java.util.concurrent.Future)3 Test (org.junit.jupiter.api.Test)3 InetSocketAddress (java.net.InetSocketAddress)1