See: Description
| Package | Description |
|---|---|
| org.graylog2.gelfclient | |
| org.graylog2.gelfclient.encoder | |
| org.graylog2.gelfclient.transport | |
| org.graylog2.gelfclient.util |
A simple GELF client library with support for different transport mechanisms.
Currently available transports are
All default transport implementations use a queue (backed by a java.util.concurrent.BlockingQueue) to send messages in a background thread to avoid blocking the calling thread until a message has been sent. That means that the org.graylog2.gelfclient.transport.GelfTransport#send(GelfMessage) and org.graylog2.gelfclient.transport.GelfTransport#trySend(GelfMessage) methods do not actually send the messages but add them to a queue where the background thread will pick them up. This is important to keep in mind when it comes to message delivery guarantees.
final GelfConfiguration config = new GelfConfiguration(new InetSocketAddress("example.com", 12201))
.transport(GelfTransports.UDP)
.queueSize(512)
.connectTimeout(5000)
.reconnectDelay(1000)
.tcpNoDelay(true)
.tcpKeepAlive(true)
.sendBufferSize(32768);
final GelfTransport transport = GelfTransports.create(config);
final GelfMessageBuilder builder = new GelfMessageBuilder("", "example.com")
.level(GelfMessageLevel.INFO)
.additionalField("_foo", "bar");
boolean blocking = false;
for (int i = 0; i < 100; i++) {
final GelfMessage message = builder.message("This is message #" + i)
.additionalField("_count", i)
.build();
if (blocking) {
// Blocks until there is capacity in the queue
transport.send(message);
} else {
// Returns false if there isn't enough room in the queue
boolean enqueued = transport.trySend(message);
}
}
Copyright © 2014–2017 Graylog, Inc.. All rights reserved.