public abstract class AbstractLogstashTcpSocketAppender<Event extends DeferredProcessingAware,Listener extends TcpAppenderListener<Event>> extends AsyncDisruptorAppender<Event,Listener>
AsyncDisruptorAppender appender that writes
events to a TCP Socket outputStream.
The behavior is similar to a SocketAppender, except that:
RingBuffer instead of a BlockingQueueEncoder instead of serialization
In addition, SSL can be enabled by setting the SSL configuration via setSsl(SSLConfiguration).
See the logback manual
for details on how to configure client-side SSL.
AsyncDisruptorAppender.LogEvent<Event>, AsyncDisruptorAppender.LogEventFactory<Event>, AsyncDisruptorAppender.LogEventTranslator<Event>| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CONNECTION_TIMEOUT
Default timeout when waiting for the remote server to accept our
connection.
|
static int |
DEFAULT_PORT
The default port number of remote logging server (4560).
|
static int |
DEFAULT_QUEUE_SIZE
Deprecated.
Use
AsyncDisruptorAppender.DEFAULT_RING_BUFFER_SIZE instead |
static int |
DEFAULT_RECONNECTION_DELAY
The default reconnection delay (30000 milliseconds or 30 seconds).
|
static String |
DEFAULT_THREAD_NAME_FORMAT |
static int |
DEFAULT_WRITE_BUFFER_SIZE |
static int |
DEFAULT_WRITE_TIMEOUT
The default write timeout in milliseconds (0 means no write timeout).
|
protected static String |
HOST_NAME_FORMAT |
protected static String |
PORT_FORMAT |
APPENDER_NAME_FORMAT, DEFAULT_DROPPED_WARN_FREQUENCY, DEFAULT_PRODUCER_TYPE, DEFAULT_RING_BUFFER_SIZE, DEFAULT_WAIT_STRATEGY, listeners, THREAD_INDEX_FORMATname, startedcontext| Constructor and Description |
|---|
AbstractLogstashTcpSocketAppender() |
| Modifier and Type | Method and Description |
|---|---|
void |
addDestination(String destination)
Adds the given destination (or destinations) to the list of potential destinations
to which to send logs.
|
void |
addDestinations(InetSocketAddress... destinations)
Adds the given destinations to the list of potential destinations.
|
protected com.lmax.disruptor.EventHandler<AsyncDisruptorAppender.LogEvent<Event>> |
createEventHandler()
Create the
EventHandler to process events as they become available from the RingBuffer. |
protected void |
fireConnectionClosed(Socket socket) |
protected void |
fireConnectionFailed(InetSocketAddress address,
Throwable throwable) |
protected void |
fireConnectionOpened(Socket socket) |
protected void |
fireEventSendFailure(Event event,
Throwable reason) |
protected void |
fireEventSent(Socket socket,
Event event,
long durationInNanos) |
Optional<InetSocketAddress> |
getConnectedDestination()
Returns the currently connected destination as an
Optional. |
DestinationConnectionStrategy |
getConnectionStrategy() |
Duration |
getConnectionTimeout()
Get the connection timeout used when establishing a TCP connection to a remote destination.
|
List<InetSocketAddress> |
getDestinations()
Return the destinations in which to attempt to send logs.
|
Encoder<Event> |
getEncoder() |
protected String |
getHostString(InetSocketAddress destination)
Returns the host string from the given destination,
avoiding a DNS hit if possible.
|
Charset |
getKeepAliveCharset() |
Duration |
getKeepAliveDuration() |
String |
getKeepAliveMessage() |
int |
getQueueSize()
Deprecated.
use
AsyncDisruptorAppender.getRingBufferSize() instead. |
Duration |
getReconnectionDelay() |
Duration |
getSecondaryConnectionTTL()
Deprecated.
|
SocketFactory |
getSocketFactory() |
SSLConfiguration |
getSsl() |
protected List<Object> |
getThreadNameFormatParams() |
int |
getWriteBufferSize() |
Duration |
getWriteTimeout() |
boolean |
isKeepAliveEnabled() |
boolean |
isStarted() |
boolean |
isWriteTimeoutEnabled()
Whether the write timeout feature is enabled or not.
|
protected Future<?> |
scheduleReaderCallable(Callable<Void> readerCallable) |
void |
setConnectionStrategy(DestinationConnectionStrategy destinationConnectionStrategy) |
void |
setConnectionTimeout(Duration connectionTimeout)
Set the connection timeout when establishing a connection to a remote destination.
|
void |
setEncoder(Encoder<Event> encoder) |
void |
setKeepAliveCharset(Charset keepAliveCharset)
The charset to use when writing the
keepAliveMessage. |
void |
setKeepAliveDuration(Duration keepAliveDuration)
If this duration elapses without an event being sent,
then the
keepAliveMessage will be sent to the socket in
order to keep the connection alive. |
void |
setKeepAliveMessage(String keepAliveMessage)
Message to send for keeping the connection alive
if
keepAliveDuration is non-null and strictly positive. |
void |
setQueueSize(int queueSize)
Deprecated.
use
AsyncDisruptorAppender.setRingBufferSize(int) instead. |
void |
setReconnectionDelay(Duration delay)
Time period for which to wait after failing to connect to all servers,
before attempting to reconnect.
|
void |
setSecondaryConnectionTTL(Duration secondaryConnectionTTL)
Deprecated.
|
void |
setSocketFactory(SocketFactory socketFactory)
Set the
SocketFactory used to create client Sockets to which to communicate. |
void |
setSsl(SSLConfiguration sslConfiguration)
Set this to non-null to use SSL.
|
void |
setThreadNameFormat(String threadNameFormat)
Pattern used by the to set the handler thread name.
|
void |
setWriteBufferSize(int writeBufferSize)
The number of bytes available in the write buffer.
|
void |
setWriteTimeout(Duration writeTimeout)
Sets the time period for which to wait for a write to complete before timing out
and attempting to reconnect to that destination.
|
void |
start() |
void |
stop() |
protected void |
updateCurrentThreadName() |
addListener, append, calculateThreadName, fireAppenderStarted, fireAppenderStopped, fireEventAppended, fireEventAppendFailed, getAppendRetryFrequency, getAppendTimeout, getDisruptor, getDroppedWarnFrequency, getEventTranslator, getProducerType, getRingBufferSize, getShutdownGracePeriod, getThreadFactory, getThreadNameFormat, getWaitStrategy, isAddDefaultStatusListener, isDaemon, isRingBufferEmpty, prepareForDeferredProcessing, removeListener, safelyFireEvent, setAddDefaultStatusListener, setAppendRetryFrequency, setAppendTimeout, setDaemon, setDroppedWarnFrequency, setEventFactory, setEventTranslator, setProducerType, setRingBufferSize, setShutdownGracePeriod, setThreadFactory, setWaitStrategy, setWaitStrategyTypeaddFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, setName, toStringaddError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContextprotected static final String HOST_NAME_FORMAT
protected static final String PORT_FORMAT
public static final String DEFAULT_THREAD_NAME_FORMAT
public static final int DEFAULT_PORT
public static final int DEFAULT_RECONNECTION_DELAY
public static final int DEFAULT_WRITE_TIMEOUT
@Deprecated public static final int DEFAULT_QUEUE_SIZE
AsyncDisruptorAppender.DEFAULT_RING_BUFFER_SIZE insteadpublic static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_WRITE_BUFFER_SIZE
protected com.lmax.disruptor.EventHandler<AsyncDisruptorAppender.LogEvent<Event>> createEventHandler()
AsyncDisruptorAppenderEventHandler to process events as they become available from the RingBuffer.
This method is invoked when the appender is started by AsyncDisruptorAppender.start() and a new Disruptor is initialized.createEventHandler in class AsyncDisruptorAppender<Event extends DeferredProcessingAware,Listener extends TcpAppenderListener<Event>>EventHandler instance.public boolean isStarted()
isStarted in interface LifeCycleisStarted in class UnsynchronizedAppenderBase<Event extends DeferredProcessingAware>public void start()
start in interface LifeCyclestart in class AsyncDisruptorAppender<Event extends DeferredProcessingAware,Listener extends TcpAppenderListener<Event>>public void stop()
stop in interface LifeCyclestop in class AsyncDisruptorAppender<Event extends DeferredProcessingAware,Listener extends TcpAppenderListener<Event>>protected void fireConnectionOpened(Socket socket)
protected void fireConnectionClosed(Socket socket)
protected void fireConnectionFailed(InetSocketAddress address, Throwable throwable)
public SocketFactory getSocketFactory()
public void setSocketFactory(SocketFactory socketFactory)
SocketFactory used to create client Sockets to which to communicate.
Use null to use the system default SocketFactory.socketFactory - the socket factory to use to create connections with remote destinations.public void addDestination(String destination) throws IllegalArgumentException
The string is a comma separated list of destinations in the form of hostName[:portNumber].
If portNumber is not provided, then the default (4560) will be used
For example, "host1.domain.com,host2.domain.com:5560"
destination - comma-separated list of destinations in the form of hostName[:portNumber]IllegalArgumentExceptionpublic void addDestinations(InetSocketAddress... destinations) throws IllegalArgumentException
destinations - the InetSocketAddress to add to the list of valid destinationsIllegalArgumentExceptionprotected String getHostString(InetSocketAddress destination)
destination - the InetSocketAddress to get the host string fromprotected void updateCurrentThreadName()
protected List<Object> getThreadNameFormatParams()
getThreadNameFormatParams in class AsyncDisruptorAppender<Event extends DeferredProcessingAware,Listener extends TcpAppenderListener<Event>>public List<InetSocketAddress> getDestinations()
InetSocketAddress representing the configured destinationspublic void setReconnectionDelay(Duration delay)
delay - the reconnection delaypublic Duration getReconnectionDelay()
@Deprecated public void setSecondaryConnectionTTL(Duration secondaryConnectionTTL)
PreferPrimaryDestinationConnectionStrategy.setSecondaryConnectionTTL(Duration) instead.PreferPrimaryDestinationConnectionStrategy.setSecondaryConnectionTTL(Duration).
When the connectionStrategy is a PreferPrimaryDestinationConnectionStrategy,
this will set its PreferPrimaryDestinationConnectionStrategy.setSecondaryConnectionTTL(Duration).secondaryConnectionTTL - the TTL of a connection when connected to a secondary destinationIllegalStateException - if the connectionStrategy is not a PreferPrimaryDestinationConnectionStrategyPreferPrimaryDestinationConnectionStrategy.setSecondaryConnectionTTL(Duration)@Deprecated public Duration getSecondaryConnectionTTL()
PreferPrimaryDestinationConnectionStrategy.getSecondaryConnectionTTL() instead.PreferPrimaryDestinationConnectionStrategy.getSecondaryConnectionTTL().null if the connection strategy is not a PreferPrimaryDestinationConnectionStrategy.getConnectionStrategy(),
PreferPrimaryDestinationConnectionStrategy.getSecondaryConnectionTTL()public void setConnectionTimeout(Duration connectionTimeout)
0 for an "infinite timeout" which often really means "use the OS defaults".connectionTimeout - connection timeoutpublic Duration getConnectionTimeout()
public int getWriteBufferSize()
public void setWriteBufferSize(int writeBufferSize)
If less than or equal to zero, buffering the output stream will be disabled. If buffering is disabled, the writer thread can slow down, but it will also can prevent dropping events in the buffer on flaky connections.
writeBufferSize - the write buffer size in bytes@Deprecated public int getQueueSize()
AsyncDisruptorAppender.getRingBufferSize() instead.AsyncDisruptorAppender.getRingBufferSize().@Deprecated public void setQueueSize(int queueSize)
AsyncDisruptorAppender.setRingBufferSize(int) instead.Must be a positive power of 2.
queueSize - the maximum number of entries in the queue.public SSLConfiguration getSsl()
public void setSsl(SSLConfiguration sslConfiguration)
sslConfiguration - the SSL configurationpublic Duration getKeepAliveDuration()
public void setKeepAliveDuration(Duration keepAliveDuration)
keepAliveMessage will be sent to the socket in
order to keep the connection alive.
When null, zero or negative, no keepAlive messages will be sent.keepAliveDuration - duration between consecutive keep alive messagespublic String getKeepAliveMessage()
public void setKeepAliveMessage(String keepAliveMessage)
keepAliveDuration is non-null and strictly positive.
The following values have special meaning:
null or empty string = no keep alive.SYSTEM" = operating system new line (default).UNIX" = unix line ending (\n).WINDOWS" = windows line ending (\r\n).Any other value will be used as-is.
keepAliveMessage - the keep alive messagepublic boolean isKeepAliveEnabled()
public boolean isWriteTimeoutEnabled()
true when the appender should try to detect write timeouts, false otherwise.public Charset getKeepAliveCharset()
public void setKeepAliveCharset(Charset keepAliveCharset)
keepAliveMessage.
Defaults to UTF-8.keepAliveCharset - charset encoding for the keep alive messagepublic void setThreadNameFormat(String threadNameFormat)
If you change the AsyncDisruptorAppender.threadFactory, then this
value may not be honored.
The string is a format pattern understood by Formatter.format(String, Object...).
Formatter.format(String, Object...) is used to
construct the actual thread name prefix.
The first argument (%1$s) is the string appender name.
The second argument (%2$d) is the numerical thread index.
The third argument (%3$s) is the string hostname of the currently connected destination.
The fourth argument (%4$d) is the numerical port of the currently connected destination.
Other arguments can be made available by subclasses.
setThreadNameFormat in class AsyncDisruptorAppender<Event extends DeferredProcessingAware,Listener extends TcpAppenderListener<Event>>threadNameFormat - thread name format patternpublic DestinationConnectionStrategy getConnectionStrategy()
public void setConnectionStrategy(DestinationConnectionStrategy destinationConnectionStrategy)
public Optional<InetSocketAddress> getConnectedDestination()
public Duration getWriteTimeout()
public void setWriteTimeout(Duration writeTimeout)
The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout which effectively means "no write timeout".
Note that since a blocking java socket output stream does not have a concept of a write timeout, a task will be scheduled with the same frequency as the write timeout in order to detect stuck writes. It is recommended to use longer write timeouts (e.g. > 30s, or minutes), rather than short write timeouts, so that this task does not execute too frequently. Also, this approach means that it could take up to two times the write timeout before a write timeout is detected.
writeTimeout - the write timeoutCopyright © 2013–2022. All rights reserved.