Class SjmsBatchEndpoint
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.DefaultEndpoint
-
- org.apache.camel.component.sjms.batch.SjmsBatchEndpoint
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.CamelContextAware
,org.apache.camel.Endpoint
,org.apache.camel.IsSingleton
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.HasId
,org.apache.camel.spi.HeaderFilterStrategyAware
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
@UriEndpoint(firstVersion="2.16.0", scheme="sjms-batch", title="Simple JMS Batch", syntax="sjms-batch:destinationName", label="messaging", consumerOnly=true) public class SjmsBatchEndpoint extends org.apache.camel.support.DefaultEndpoint implements org.apache.camel.spi.HeaderFilterStrategyAware
Highly performant and transactional batch consumption of messages from a JMS queue.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_COMPLETION_SIZE
static int
DEFAULT_COMPLETION_TIMEOUT
-
Constructor Summary
Constructors Constructor Description SjmsBatchEndpoint()
SjmsBatchEndpoint(String endpointUri, org.apache.camel.Component component, String remaining)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected JmsBinding
createBinding()
Creates theJmsBinding
to use.org.apache.camel.Consumer
createConsumer(org.apache.camel.Processor processor)
org.apache.camel.Exchange
createExchange(javax.jms.Message message, javax.jms.Session session)
org.apache.camel.Producer
createProducer()
org.apache.camel.AggregationStrategy
getAggregationStrategy()
JmsBinding
getBinding()
int
getCompletionInterval()
org.apache.camel.Predicate
getCompletionPredicate()
int
getCompletionSize()
int
getCompletionTimeout()
SjmsBatchComponent
getComponent()
int
getConsumerCount()
String
getDestinationName()
The destination name.org.apache.camel.spi.HeaderFilterStrategy
getHeaderFilterStrategy()
JmsKeyFormatStrategy
getJmsKeyFormatStrategy()
int
getKeepAliveDelay()
MessageCreatedStrategy
getMessageCreatedStrategy()
int
getPollDuration()
int
getRecoveryInterval()
ScheduledExecutorService
getTimeoutCheckerExecutorService()
boolean
isAllowNullBody()
boolean
isAsyncStartListener()
boolean
isEagerCheckCompletion()
boolean
isIncludeAllJMSXProperties()
boolean
isMapJmsMessage()
boolean
isSendEmptyMessageWhenIdle()
void
setAggregationStrategy(org.apache.camel.AggregationStrategy aggregationStrategy)
The aggregation strategy to use, which merges all the batched messages into a single messagevoid
setAllowNullBody(boolean allowNullBody)
Whether to allow sending messages with no body.void
setAsyncStartListener(boolean asyncStartListener)
Whether to startup the consumer message listener asynchronously, when starting a route.void
setBinding(JmsBinding binding)
Sets the binding used to convert from a Camel message to and from a JMS messagevoid
setCompletionInterval(int completionInterval)
The completion interval in millis, which causes batches to be completed in a scheduled fixed rate every interval.void
setCompletionPredicate(String predicate)
void
setCompletionPredicate(org.apache.camel.Predicate completionPredicate)
The completion predicate, which causes batches to be completed when the predicate evaluates as true.void
setCompletionSize(int completionSize)
The number of messages consumed at which the batch will be completedvoid
setCompletionTimeout(int completionTimeout)
The timeout in millis from receipt of the first first message when the batch will be completed.void
setConsumerCount(int consumerCount)
The number of JMS sessions to consume fromvoid
setEagerCheckCompletion(boolean eagerCheckCompletion)
Use eager completion checking which means that the completionPredicate will use the incoming Exchange.void
setHeaderFilterStrategy(org.apache.camel.spi.HeaderFilterStrategy strategy)
To use a custom HeaderFilterStrategy to filter header to and from Camel message.void
setIncludeAllJMSXProperties(boolean includeAllJMSXProperties)
Whether to include all JMSXxxx properties when mapping from JMS to Camel Message.void
setJmsKeyFormatStrategy(JmsKeyFormatStrategy jmsKeyFormatStrategy)
Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification.void
setKeepAliveDelay(int keepAliveDelay)
The delay in millis between attempts to re-establish a valid session.void
setMapJmsMessage(boolean mapJmsMessage)
Specifies whether Camel should auto map the received JMS message to a suited payload type, such as javax.jms.TextMessage to a String etc.void
setMessageCreatedStrategy(MessageCreatedStrategy messageCreatedStrategy)
To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of javax.jms.Message objects when Camel is sending a JMS message.void
setPollDuration(int pollDuration)
The duration in milliseconds of each poll for messages.void
setRecoveryInterval(int recoveryInterval)
Specifies the interval between recovery attempts, i.e.void
setSendEmptyMessageWhenIdle(boolean sendEmptyMessageWhenIdle)
If using completion timeout or interval, then the batch may be empty if the timeout triggered and there was no messages in the batch.void
setTimeoutCheckerExecutorService(ScheduledExecutorService timeoutCheckerExecutorService)
If using the completionInterval option a background thread is created to trigger the completion interval.-
Methods inherited from class org.apache.camel.support.DefaultEndpoint
configureConsumer, configurePollingConsumer, configureProperties, createAsyncProducer, createEndpointUri, createExchange, createExchange, createPollingConsumer, doInit, doStart, doStop, equals, getCamelContext, getEndpointKey, getEndpointUri, getExceptionHandler, getExchangePattern, getId, getPollingConsumerBlockTimeout, getPollingConsumerQueueSize, hashCode, isBasicPropertyBinding, isBridgeErrorHandler, isLazyStartProducer, isLenientProperties, isPollingConsumerBlockWhenFull, isSingleton, isSynchronous, setBasicPropertyBinding, setBridgeErrorHandler, setCamelContext, setComponent, setEndpointUri, setEndpointUriIfNotSpecified, setExceptionHandler, setExchangePattern, setLazyStartProducer, setPollingConsumerBlockTimeout, setPollingConsumerBlockWhenFull, setPollingConsumerQueueSize, setProperties, setSynchronous, toString
-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
DEFAULT_COMPLETION_SIZE
public static final int DEFAULT_COMPLETION_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_COMPLETION_TIMEOUT
public static final int DEFAULT_COMPLETION_TIMEOUT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getComponent
public SjmsBatchComponent getComponent()
- Overrides:
getComponent
in classorg.apache.camel.support.DefaultEndpoint
-
createProducer
public org.apache.camel.Producer createProducer() throws Exception
- Specified by:
createProducer
in interfaceorg.apache.camel.Endpoint
- Throws:
Exception
-
createConsumer
public org.apache.camel.Consumer createConsumer(org.apache.camel.Processor processor) throws Exception
- Specified by:
createConsumer
in interfaceorg.apache.camel.Endpoint
- Throws:
Exception
-
createExchange
public org.apache.camel.Exchange createExchange(javax.jms.Message message, javax.jms.Session session)
-
getBinding
public JmsBinding getBinding()
-
createBinding
protected JmsBinding createBinding()
Creates theJmsBinding
to use.
-
setBinding
public void setBinding(JmsBinding binding)
Sets the binding used to convert from a Camel message to and from a JMS message
-
getAggregationStrategy
public org.apache.camel.AggregationStrategy getAggregationStrategy()
-
setAggregationStrategy
public void setAggregationStrategy(org.apache.camel.AggregationStrategy aggregationStrategy)
The aggregation strategy to use, which merges all the batched messages into a single message
-
getDestinationName
public String getDestinationName()
The destination name. Only queues are supported, names may be prefixed by 'queue:'.
-
getConsumerCount
public int getConsumerCount()
-
setConsumerCount
public void setConsumerCount(int consumerCount)
The number of JMS sessions to consume from
-
getCompletionSize
public int getCompletionSize()
-
setCompletionSize
public void setCompletionSize(int completionSize)
The number of messages consumed at which the batch will be completed
-
getCompletionTimeout
public int getCompletionTimeout()
-
setCompletionTimeout
public void setCompletionTimeout(int completionTimeout)
The timeout in millis from receipt of the first first message when the batch will be completed. The batch may be empty if the timeout triggered and there was no messages in the batch.
Notice you cannot use both completion timeout and completion interval at the same time, only one can be configured.
-
getCompletionInterval
public int getCompletionInterval()
-
setCompletionInterval
public void setCompletionInterval(int completionInterval)
The completion interval in millis, which causes batches to be completed in a scheduled fixed rate every interval. The batch may be empty if the timeout triggered and there was no messages in the batch.
Notice you cannot use both completion timeout and completion interval at the same time, only one can be configured.
-
getCompletionPredicate
public org.apache.camel.Predicate getCompletionPredicate()
-
setCompletionPredicate
public void setCompletionPredicate(org.apache.camel.Predicate completionPredicate)
The completion predicate, which causes batches to be completed when the predicate evaluates as true. The predicate can also be configured using the simple language using the string syntax. You may want to set the option eagerCheckCompletion to true to let the predicate match the incoming message, as otherwise it matches the aggregated message.
-
setCompletionPredicate
public void setCompletionPredicate(String predicate)
-
isEagerCheckCompletion
public boolean isEagerCheckCompletion()
-
setEagerCheckCompletion
public void setEagerCheckCompletion(boolean eagerCheckCompletion)
Use eager completion checking which means that the completionPredicate will use the incoming Exchange. As opposed to without eager completion checking the completionPredicate will use the aggregated Exchange.
-
isSendEmptyMessageWhenIdle
public boolean isSendEmptyMessageWhenIdle()
-
setSendEmptyMessageWhenIdle
public void setSendEmptyMessageWhenIdle(boolean sendEmptyMessageWhenIdle)
If using completion timeout or interval, then the batch may be empty if the timeout triggered and there was no messages in the batch. If this option is true and the batch is empty then an empty message is added to the batch so an empty message is routed.
-
getPollDuration
public int getPollDuration()
-
setPollDuration
public void setPollDuration(int pollDuration)
The duration in milliseconds of each poll for messages. completionTimeOut will be used if it is shorter and a batch has started.
-
isAllowNullBody
public boolean isAllowNullBody()
-
setAllowNullBody
public void setAllowNullBody(boolean allowNullBody)
Whether to allow sending messages with no body. If this option is false and the message body is null, then an JMSException is thrown.
-
isMapJmsMessage
public boolean isMapJmsMessage()
-
setMapJmsMessage
public void setMapJmsMessage(boolean mapJmsMessage)
Specifies whether Camel should auto map the received JMS message to a suited payload type, such as javax.jms.TextMessage to a String etc. See section about how mapping works below for more details.
-
getMessageCreatedStrategy
public MessageCreatedStrategy getMessageCreatedStrategy()
-
setMessageCreatedStrategy
public void setMessageCreatedStrategy(MessageCreatedStrategy messageCreatedStrategy)
To use the given MessageCreatedStrategy which are invoked when Camel creates new instances of javax.jms.Message objects when Camel is sending a JMS message.
-
getJmsKeyFormatStrategy
public JmsKeyFormatStrategy getJmsKeyFormatStrategy()
-
setJmsKeyFormatStrategy
public void setJmsKeyFormatStrategy(JmsKeyFormatStrategy jmsKeyFormatStrategy)
Pluggable strategy for encoding and decoding JMS keys so they can be compliant with the JMS specification. Camel provides two implementations out of the box: default and passthrough. The default strategy will safely marshal dots and hyphens (. and -). The passthrough strategy leaves the key as is. Can be used for JMS brokers which do not care whether JMS header keys contain illegal characters. You can provide your own implementation of the org.apache.camel.component.jms.JmsKeyFormatStrategy and refer to it using the # notation.
-
getHeaderFilterStrategy
public org.apache.camel.spi.HeaderFilterStrategy getHeaderFilterStrategy()
- Specified by:
getHeaderFilterStrategy
in interfaceorg.apache.camel.spi.HeaderFilterStrategyAware
-
setHeaderFilterStrategy
public void setHeaderFilterStrategy(org.apache.camel.spi.HeaderFilterStrategy strategy)
To use a custom HeaderFilterStrategy to filter header to and from Camel message.- Specified by:
setHeaderFilterStrategy
in interfaceorg.apache.camel.spi.HeaderFilterStrategyAware
-
isIncludeAllJMSXProperties
public boolean isIncludeAllJMSXProperties()
-
setIncludeAllJMSXProperties
public void setIncludeAllJMSXProperties(boolean includeAllJMSXProperties)
Whether to include all JMSXxxx properties when mapping from JMS to Camel Message. Setting this to true will include properties such as JMSXAppID, and JMSXUserID etc. Note: If you are using a custom headerFilterStrategy then this option does not apply.
-
getTimeoutCheckerExecutorService
public ScheduledExecutorService getTimeoutCheckerExecutorService()
-
setTimeoutCheckerExecutorService
public void setTimeoutCheckerExecutorService(ScheduledExecutorService timeoutCheckerExecutorService)
If using the completionInterval option a background thread is created to trigger the completion interval. Set this option to provide a custom thread pool to be used rather than creating a new thread for every consumer.
-
isAsyncStartListener
public boolean isAsyncStartListener()
-
setAsyncStartListener
public void setAsyncStartListener(boolean asyncStartListener)
Whether to startup the consumer message listener asynchronously, when starting a route. For example if a JmsConsumer cannot get a connection to a remote JMS broker, then it may block while retrying and/or failover. This will cause Camel to block while starting routes. By setting this option to true, you will let routes startup, while the JmsConsumer connects to the JMS broker using a dedicated thread in asynchronous mode. If this option is used, then beware that if the connection could not be established, then an exception is logged at WARN level, and the consumer will not be able to receive messages; You can then restart the route to retry.
-
getRecoveryInterval
public int getRecoveryInterval()
-
setRecoveryInterval
public void setRecoveryInterval(int recoveryInterval)
Specifies the interval between recovery attempts, i.e. when a connection is being refreshed, in milliseconds. The default is 5000 ms, that is, 5 seconds.
-
setKeepAliveDelay
public void setKeepAliveDelay(int keepAliveDelay)
The delay in millis between attempts to re-establish a valid session. If this is a positive value the SjmsBatchConsumer will attempt to create a new session if it sees an IllegalStateException during message consumption. This delay value allows you to pause between attempts to prevent spamming the logs. If this is a negative value (default is -1) then the SjmsBatchConsumer will behave as it always has before - that is it will bail out and the route will shut down if it sees an IllegalStateException.
-
getKeepAliveDelay
public int getKeepAliveDelay()
-
-