Package org.apache.camel.component.netty
Class NettyConfiguration
- java.lang.Object
-
- org.apache.camel.component.netty.NettyServerBootstrapConfiguration
-
- org.apache.camel.component.netty.NettyConfiguration
-
- All Implemented Interfaces:
Cloneable
@UriParams @Configurer public class NettyConfiguration extends NettyServerBootstrapConfiguration implements Cloneable
-
-
Field Summary
-
Fields inherited from class org.apache.camel.component.netty.NettyServerBootstrapConfiguration
backlog, bossCount, bossGroup, broadcast, channelGroup, connectTimeout, DEFAULT_ENABLED_PROTOCOLS, enabledProtocols, host, keepAlive, keyStoreFile, keyStoreFormat, keyStoreResource, nativeTransport, needClientAuth, nettyServerBootstrapFactory, networkInterface, options, passphrase, port, protocol, receiveBufferSize, receiveBufferSizePredictor, reuseAddress, securityProvider, sendBufferSize, serverInitializerFactory, ssl, sslClientCertHeaders, sslContextParameters, sslHandler, tcpNoDelay, trustStoreFile, trustStoreResource, workerCount, workerGroup
-
-
Constructor Summary
Constructors Constructor Description NettyConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addDecoder(io.netty.channel.ChannelHandler decoder)
Adds a custom ChannelHandler class that can be used to perform special marshalling of inbound payloads.void
addEncoder(io.netty.channel.ChannelHandler encoder)
Adds a custom ChannelHandler class that can be used to perform special marshalling of outbound payloads.NettyConfiguration
copy()
Returns a copy of this configurationString
getCharsetName()
ClientInitializerFactory
getClientInitializerFactory()
ClientInitializerFactory
getClientPipelineFactory()
Deprecated.use #getClientInitializerFactoryNettyCamelStateCorrelationManager
getCorrelationManager()
int
getDecoderMaxLineLength()
String
getDecoders()
List<io.netty.channel.ChannelHandler>
getDecodersAsList()
TextLineDelimiter
getDelimiter()
String
getEncoders()
List<io.netty.channel.ChannelHandler>
getEncodersAsList()
String
getEncoding()
org.apache.camel.LoggingLevel
getNoReplyLogLevel()
int
getProducerPoolMaxIdle()
int
getProducerPoolMaxTotal()
long
getProducerPoolMinEvictableIdle()
int
getProducerPoolMinIdle()
long
getRequestTimeout()
org.apache.camel.LoggingLevel
getServerClosedChannelExceptionCaughtLogLevel()
org.apache.camel.LoggingLevel
getServerExceptionCaughtLogLevel()
boolean
isAllowDefaultCodec()
boolean
isAllowSerializedHeaders()
boolean
isAutoAppendDelimiter()
boolean
isClientMode()
boolean
isDisconnect()
boolean
isDisconnectOnNoReply()
boolean
isHostnameVerification()
boolean
isLazyChannelCreation()
boolean
isProducerPoolEnabled()
boolean
isReuseChannel()
boolean
isSync()
boolean
isTextline()
boolean
isTransferExchange()
boolean
isUdpByteArrayCodec()
boolean
isUdpConnectionlessSending()
boolean
isUseByteBuf()
boolean
isUsingExecutorService()
void
parseURI(URI uri, Map<String,Object> parameters, NettyComponent component, String... supportedProtocols)
void
setAllowDefaultCodec(boolean allowDefaultCodec)
The netty component installs a default codec if both, encoder/decoder is null and textline is false.void
setAllowSerializedHeaders(boolean allowSerializedHeaders)
Only used for TCP when transferExchange is true.void
setAutoAppendDelimiter(boolean autoAppendDelimiter)
Whether or not to auto append missing end delimiter when sending using the textline codec.void
setClientInitializerFactory(ClientInitializerFactory clientInitializerFactory)
To use a custom ClientInitializerFactoryvoid
setClientMode(boolean clientMode)
If the clientMode is true, netty consumer will connect the address as a TCP client.void
setClientPipelineFactory(ClientInitializerFactory clientPipelineFactory)
Deprecated.use #setClientInitializerFactoryvoid
setCorrelationManager(NettyCamelStateCorrelationManager correlationManager)
To use a custom correlation manager to manage how request and reply messages are mapped when using request/reply with the netty producer.void
setDecoderMaxLineLength(int decoderMaxLineLength)
The max line length to use for the textline codec.void
setDecoders(String decoders)
A list of decoders to be used.void
setDecoders(List<io.netty.channel.ChannelHandler> decoders)
A list of decoders to be used.void
setDecodersAsList(List<io.netty.channel.ChannelHandler> decoders)
void
setDelimiter(TextLineDelimiter delimiter)
The delimiter to use for the textline codec.void
setDisconnect(boolean disconnect)
Whether or not to disconnect(close) from Netty Channel right after use.void
setDisconnectOnNoReply(boolean disconnectOnNoReply)
If sync is enabled then this option dictates NettyConsumer if it should disconnect where there is no reply to send back.void
setEncoders(String encoders)
A list of encoders to be used.void
setEncoders(List<io.netty.channel.ChannelHandler> encoders)
A list of encoders to be used.void
setEncodersAsList(List<io.netty.channel.ChannelHandler> encoders)
void
setEncoding(String encoding)
The encoding (a charset name) to use for the textline codec.void
setHostnameVerification(boolean hostnameVerification)
To enable/disable hostname verification on SSLEnginevoid
setLazyChannelCreation(boolean lazyChannelCreation)
Channels can be lazily created to avoid exceptions, if the remote server is not up and running when the Camel producer is started.void
setNoReplyLogLevel(org.apache.camel.LoggingLevel noReplyLogLevel)
If sync is enabled this option dictates NettyConsumer which logging level to use when logging a there is no reply to send back.void
setProducerPoolEnabled(boolean producerPoolEnabled)
Whether producer pool is enabled or not.void
setProducerPoolMaxIdle(int producerPoolMaxIdle)
Sets the cap on the number of "idle" instances in the pool.void
setProducerPoolMaxTotal(int producerPoolMaxTotal)
Sets the cap on the number of objects that can be allocated by the pool (checked out to clients, or idle awaiting checkout) at a given time.void
setProducerPoolMinEvictableIdle(long producerPoolMinEvictableIdle)
Sets the minimum amount of time (value in millis) an object may sit idle in the pool before it is eligible for eviction by the idle object evictor.void
setProducerPoolMinIdle(int producerPoolMinIdle)
Sets the minimum number of instances allowed in the producer pool before the evictor thread (if active) spawns new objects.void
setRequestTimeout(long requestTimeout)
Allows to use a timeout for the Netty producer when calling a remote server.void
setReuseChannel(boolean reuseChannel)
This option allows producers and consumers (in client mode) to reuse the same NettyChannel
for the lifecycle of processing theExchange
.void
setServerClosedChannelExceptionCaughtLogLevel(org.apache.camel.LoggingLevel serverClosedChannelExceptionCaughtLogLevel)
If the server (NettyConsumer) catches an java.nio.channels.ClosedChannelException then its logged using this logging level.void
setServerExceptionCaughtLogLevel(org.apache.camel.LoggingLevel serverExceptionCaughtLogLevel)
If the server (NettyConsumer) catches an exception then its logged using this logging level.void
setSync(boolean sync)
Setting to set endpoint as one-way or request-responsevoid
setTextline(boolean textline)
Only used for TCP.void
setTransferExchange(boolean transferExchange)
Only used for TCP.void
setUdpByteArrayCodec(boolean udpByteArrayCodec)
For UDP only.void
setUdpConnectionlessSending(boolean udpConnectionlessSending)
This option supports connection less udp sending which is a real fire and forget.void
setUseByteBuf(boolean useByteBuf)
If the useByteBuf is true, netty producer will turn the message body intoByteBuf
before sending it out.void
setUsingExecutorService(boolean usingExecutorService)
Whether to use ordered thread pool, to ensure events are processed orderly on the same channel.void
validateConfiguration()
-
Methods inherited from class org.apache.camel.component.netty.NettyServerBootstrapConfiguration
compatible, getAddress, getBacklog, getBossCount, getBossGroup, getChannelGroup, getConnectTimeout, getEnabledProtocols, getHost, getKeyStoreFile, getKeyStoreFormat, getKeyStoreResource, getNettyServerBootstrapFactory, getNetworkInterface, getOptions, getPassphrase, getPort, getProtocol, getReceiveBufferSize, getReceiveBufferSizePredictor, getReconnectInterval, getSecurityProvider, getSendBufferSize, getServerInitializerFactory, getServerPipelineFactory, getSslContextParameters, getSslHandler, getTrustStoreFile, getTrustStoreResource, getWorkerCount, getWorkerGroup, isBroadcast, isKeepAlive, isNativeTransport, isNeedClientAuth, isReconnect, isReuseAddress, isSsl, isSslClientCertHeaders, isTcp, isTcpNoDelay, setBacklog, setBossCount, setBossGroup, setBroadcast, setChannelGroup, setConnectTimeout, setEnabledProtocols, setHost, setKeepAlive, setKeyStoreFile, setKeyStoreFormat, setKeyStoreResource, setNativeTransport, setNeedClientAuth, setNettyServerBootstrapFactory, setNetworkInterface, setOptions, setPassphrase, setPort, setProtocol, setReceiveBufferSize, setReceiveBufferSizePredictor, setReconnect, setReconnectInterval, setReuseAddress, setSecurityProvider, setSendBufferSize, setServerInitializerFactory, setServerPipelineFactory, setSsl, setSslClientCertHeaders, setSslContextParameters, setSslHandler, setTcpNoDelay, setTrustStoreFile, setTrustStoreResource, setWorkerCount, setWorkerGroup, toStringBootstrapConfiguration
-
-
-
-
Method Detail
-
copy
public NettyConfiguration copy()
Returns a copy of this configuration
-
validateConfiguration
public void validateConfiguration()
-
parseURI
public void parseURI(URI uri, Map<String,Object> parameters, NettyComponent component, String... supportedProtocols) throws Exception
- Throws:
Exception
-
getCharsetName
public String getCharsetName()
-
getRequestTimeout
public long getRequestTimeout()
-
setRequestTimeout
public void setRequestTimeout(long requestTimeout)
Allows to use a timeout for the Netty producer when calling a remote server. By default no timeout is in use. The value is in milli seconds, so eg 30000 is 30 seconds. The requestTimeout is using Netty's ReadTimeoutHandler to trigger the timeout.
-
isSync
public boolean isSync()
-
setSync
public void setSync(boolean sync)
Setting to set endpoint as one-way or request-response
-
isTextline
public boolean isTextline()
-
setTextline
public void setTextline(boolean textline)
Only used for TCP. If no codec is specified, you can use this flag to indicate a text line based codec; if not specified or the value is false, then Object Serialization is assumed over TCP - however only Strings are allowed to be serialized by default.
-
getDecoderMaxLineLength
public int getDecoderMaxLineLength()
-
setDecoderMaxLineLength
public void setDecoderMaxLineLength(int decoderMaxLineLength)
The max line length to use for the textline codec.
-
getDelimiter
public TextLineDelimiter getDelimiter()
-
setDelimiter
public void setDelimiter(TextLineDelimiter delimiter)
The delimiter to use for the textline codec. Possible values are LINE and NULL.
-
isAutoAppendDelimiter
public boolean isAutoAppendDelimiter()
-
setAutoAppendDelimiter
public void setAutoAppendDelimiter(boolean autoAppendDelimiter)
Whether or not to auto append missing end delimiter when sending using the textline codec.
-
getEncoding
public String getEncoding()
-
setEncoding
public void setEncoding(String encoding)
The encoding (a charset name) to use for the textline codec. If not provided, Camel will use the JVM default Charset.
-
getDecodersAsList
public List<io.netty.channel.ChannelHandler> getDecodersAsList()
-
setDecodersAsList
public void setDecodersAsList(List<io.netty.channel.ChannelHandler> decoders)
-
setDecoders
public void setDecoders(List<io.netty.channel.ChannelHandler> decoders)
A list of decoders to be used. You can use a String which have values separated by comma, and have the values be looked up in the Registry. Just remember to prefix the value with # so Camel knows it should lookup.
-
setDecoders
public void setDecoders(String decoders)
A list of decoders to be used. You can use a String which have values separated by comma, and have the values be looked up in the Registry. Just remember to prefix the value with # so Camel knows it should lookup.
-
getDecoders
public String getDecoders()
-
getEncodersAsList
public List<io.netty.channel.ChannelHandler> getEncodersAsList()
-
setEncodersAsList
public void setEncodersAsList(List<io.netty.channel.ChannelHandler> encoders)
-
setEncoders
public void setEncoders(List<io.netty.channel.ChannelHandler> encoders)
A list of encoders to be used. You can use a String which have values separated by comma, and have the values be looked up in the Registry. Just remember to prefix the value with # so Camel knows it should lookup.
-
setEncoders
public void setEncoders(String encoders)
A list of encoders to be used. You can use a String which have values separated by comma, and have the values be looked up in the Registry. Just remember to prefix the value with # so Camel knows it should lookup.
-
getEncoders
public String getEncoders()
-
addEncoder
public void addEncoder(io.netty.channel.ChannelHandler encoder)
Adds a custom ChannelHandler class that can be used to perform special marshalling of outbound payloads.
-
addDecoder
public void addDecoder(io.netty.channel.ChannelHandler decoder)
Adds a custom ChannelHandler class that can be used to perform special marshalling of inbound payloads.
-
isDisconnect
public boolean isDisconnect()
-
setDisconnect
public void setDisconnect(boolean disconnect)
Whether or not to disconnect(close) from Netty Channel right after use. Can be used for both consumer and producer.
-
isLazyChannelCreation
public boolean isLazyChannelCreation()
-
setLazyChannelCreation
public void setLazyChannelCreation(boolean lazyChannelCreation)
Channels can be lazily created to avoid exceptions, if the remote server is not up and running when the Camel producer is started.
-
isTransferExchange
public boolean isTransferExchange()
-
setTransferExchange
public void setTransferExchange(boolean transferExchange)
Only used for TCP. You can transfer the exchange over the wire instead of just the body. The following fields are transferred: In body, Out body, fault body, In headers, Out headers, fault headers, exchange properties, exchange exception. This requires that the objects are serializable. Camel will exclude any non-serializable objects and log it at WARN level.
-
isAllowSerializedHeaders
public boolean isAllowSerializedHeaders()
-
setAllowSerializedHeaders
public void setAllowSerializedHeaders(boolean allowSerializedHeaders)
Only used for TCP when transferExchange is true. When set to true, serializable objects in headers and properties will be added to the exchange. Otherwise Camel will exclude any non-serializable objects and log it at WARN level.
-
isDisconnectOnNoReply
public boolean isDisconnectOnNoReply()
-
setDisconnectOnNoReply
public void setDisconnectOnNoReply(boolean disconnectOnNoReply)
If sync is enabled then this option dictates NettyConsumer if it should disconnect where there is no reply to send back.
-
getNoReplyLogLevel
public org.apache.camel.LoggingLevel getNoReplyLogLevel()
-
setNoReplyLogLevel
public void setNoReplyLogLevel(org.apache.camel.LoggingLevel noReplyLogLevel)
If sync is enabled this option dictates NettyConsumer which logging level to use when logging a there is no reply to send back.
-
getServerExceptionCaughtLogLevel
public org.apache.camel.LoggingLevel getServerExceptionCaughtLogLevel()
-
setServerExceptionCaughtLogLevel
public void setServerExceptionCaughtLogLevel(org.apache.camel.LoggingLevel serverExceptionCaughtLogLevel)
If the server (NettyConsumer) catches an exception then its logged using this logging level.
-
getServerClosedChannelExceptionCaughtLogLevel
public org.apache.camel.LoggingLevel getServerClosedChannelExceptionCaughtLogLevel()
-
setServerClosedChannelExceptionCaughtLogLevel
public void setServerClosedChannelExceptionCaughtLogLevel(org.apache.camel.LoggingLevel serverClosedChannelExceptionCaughtLogLevel)
If the server (NettyConsumer) catches an java.nio.channels.ClosedChannelException then its logged using this logging level. This is used to avoid logging the closed channel exceptions, as clients can disconnect abruptly and then cause a flood of closed exceptions in the Netty server.
-
isAllowDefaultCodec
public boolean isAllowDefaultCodec()
-
setAllowDefaultCodec
public void setAllowDefaultCodec(boolean allowDefaultCodec)
The netty component installs a default codec if both, encoder/decoder is null and textline is false. Setting allowDefaultCodec to false prevents the netty component from installing a default codec as the first element in the filter chain.
-
setClientPipelineFactory
@Deprecated public void setClientPipelineFactory(ClientInitializerFactory clientPipelineFactory)
Deprecated.use #setClientInitializerFactory
-
getClientPipelineFactory
@Deprecated public ClientInitializerFactory getClientPipelineFactory()
Deprecated.use #getClientInitializerFactory
-
getClientInitializerFactory
public ClientInitializerFactory getClientInitializerFactory()
-
setClientInitializerFactory
public void setClientInitializerFactory(ClientInitializerFactory clientInitializerFactory)
To use a custom ClientInitializerFactory
-
isUsingExecutorService
public boolean isUsingExecutorService()
-
setUsingExecutorService
public void setUsingExecutorService(boolean usingExecutorService)
Whether to use ordered thread pool, to ensure events are processed orderly on the same channel.
-
getProducerPoolMaxTotal
public int getProducerPoolMaxTotal()
-
setProducerPoolMaxTotal
public void setProducerPoolMaxTotal(int producerPoolMaxTotal)
Sets the cap on the number of objects that can be allocated by the pool (checked out to clients, or idle awaiting checkout) at a given time. Use a negative value for no limit.
-
getProducerPoolMinIdle
public int getProducerPoolMinIdle()
-
setProducerPoolMinIdle
public void setProducerPoolMinIdle(int producerPoolMinIdle)
Sets the minimum number of instances allowed in the producer pool before the evictor thread (if active) spawns new objects.
-
getProducerPoolMaxIdle
public int getProducerPoolMaxIdle()
-
setProducerPoolMaxIdle
public void setProducerPoolMaxIdle(int producerPoolMaxIdle)
Sets the cap on the number of "idle" instances in the pool.
-
getProducerPoolMinEvictableIdle
public long getProducerPoolMinEvictableIdle()
-
setProducerPoolMinEvictableIdle
public void setProducerPoolMinEvictableIdle(long producerPoolMinEvictableIdle)
Sets the minimum amount of time (value in millis) an object may sit idle in the pool before it is eligible for eviction by the idle object evictor.
-
isProducerPoolEnabled
public boolean isProducerPoolEnabled()
-
setProducerPoolEnabled
public void setProducerPoolEnabled(boolean producerPoolEnabled)
Whether producer pool is enabled or not.Important: If you turn this off then a single shared connection is used for the producer, also if you are doing request/reply. That means there is a potential issue with interleaved responses if replies comes back out-of-order. Therefore you need to have a correlation id in both the request and reply messages so you can properly correlate the replies to the Camel callback that is responsible for continue processing the message in Camel. To do this you need to implement
See also the correlationManager option for more details.NettyCamelStateCorrelationManager
as correlation manager and configure it via the correlationManager option.
-
isUdpConnectionlessSending
public boolean isUdpConnectionlessSending()
-
setUdpConnectionlessSending
public void setUdpConnectionlessSending(boolean udpConnectionlessSending)
This option supports connection less udp sending which is a real fire and forget. A connected udp send receive the PortUnreachableException if no one is listen on the receiving port.
-
isClientMode
public boolean isClientMode()
-
setClientMode
public void setClientMode(boolean clientMode)
If the clientMode is true, netty consumer will connect the address as a TCP client.
-
isUseByteBuf
public boolean isUseByteBuf()
-
setUseByteBuf
public void setUseByteBuf(boolean useByteBuf)
If the useByteBuf is true, netty producer will turn the message body intoByteBuf
before sending it out.
-
isUdpByteArrayCodec
public boolean isUdpByteArrayCodec()
-
setUdpByteArrayCodec
public void setUdpByteArrayCodec(boolean udpByteArrayCodec)
For UDP only. If enabled the using byte array codec instead of Java serialization protocol.
-
isReuseChannel
public boolean isReuseChannel()
-
setReuseChannel
public void setReuseChannel(boolean reuseChannel)
This option allows producers and consumers (in client mode) to reuse the same NettyChannel
for the lifecycle of processing theExchange
. This is useful if you need to call a server multiple times in a Camel route and want to use the same network connection. When using this, the channel is not returned to the connection pool until theExchange
is done; or disconnected if the disconnect option is set to true. The reusedChannel
is stored on theExchange
as an exchange property with the keyNettyConstants.NETTY_CHANNEL
which allows you to obtain the channel during routing and use it as well.
-
getCorrelationManager
public NettyCamelStateCorrelationManager getCorrelationManager()
-
setCorrelationManager
public void setCorrelationManager(NettyCamelStateCorrelationManager correlationManager)
To use a custom correlation manager to manage how request and reply messages are mapped when using request/reply with the netty producer. This should only be used if you have a way to map requests together with replies such as if there is correlation ids in both the request and reply messages. This can be used if you want to multiplex concurrent messages on the same channel (aka connection) in netty. When doing this you must have a way to correlate the request and reply messages so you can store the right reply on the inflight Camel Exchange before its continued routed. We recommend extending theTimeoutCorrelationManagerSupport
when you build custom correlation managers. This provides support for timeout and other complexities you otherwise would need to implement as well. See also the producerPoolEnabled option for more details.
-
isHostnameVerification
public boolean isHostnameVerification()
-
setHostnameVerification
public void setHostnameVerification(boolean hostnameVerification)
To enable/disable hostname verification on SSLEngine
-
-