Class StreamEndpoint

java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.DefaultEndpoint
org.apache.camel.component.stream.StreamEndpoint
All Implemented Interfaces:
AutoCloseable, org.apache.camel.CamelContextAware, org.apache.camel.ComponentAware, org.apache.camel.Endpoint, org.apache.camel.IsSingleton, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.HasCamelContext, org.apache.camel.spi.HasId, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

@UriEndpoint(firstVersion="1.3.0", scheme="stream", title="Stream", syntax="stream:kind", category={FILE,CORE}, headersClass=StreamConstants.class) public class StreamEndpoint extends org.apache.camel.support.DefaultEndpoint
Read from system-in and write to system-out and system-err streams.
  • Field Summary

    Fields inherited from class org.apache.camel.support.service.BaseService

    BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
  • Constructor Summary

    Constructors
    Constructor
    Description
    StreamEndpoint(String endpointUri, org.apache.camel.Component component)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.camel.Consumer
    createConsumer(org.apache.camel.Processor processor)
     
    org.apache.camel.Producer
     
    protected void
     
    int
     
     
    long
     
     
     
    int
     
     
     
     
    long
     
     
    long
     
     
    int
     
    long
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    boolean
     
    void
    setAppendNewLine(boolean appendNewLine)
    Whether to append a new line character at end of output.
    void
    setAutoCloseCount(int autoCloseCount)
    Number of messages to process before closing stream on Producer side.
    void
    setCloseOnDone(boolean closeOnDone)
    This option is used in combination with Splitter and streaming to the same file.
    void
    setDelay(long delay)
    Initial delay in milliseconds before producing the stream.
    void
    setEncoding(String encoding)
    You can configure the encoding (is a charset name) to use text-based streams (for example, message body is a String object).
    void
    setFileName(String fileName)
    When using the stream:file URI format, this option specifies the filename to stream to/from.
    void
    setFileWatcher(boolean fileWatcher)
    To use JVM file watcher to listen for file change events to support re-loading files that may be overwritten, somewhat like tail --retry
    void
    setGroupLines(int groupLines)
    To group X number of lines in the consumer.
    void
    Allows to use a custom GroupStrategy to control how to group lines.
    void
    setHttpHeaders(String httpHeaders)
    When using stream:http format, this option specifies optional http headers, such as Accept: application/json.
    void
    setHttpUrl(String httpUrl)
    When using stream:http format, this option specifies the http url to stream from.
    void
    setInitialPromptDelay(long initialPromptDelay)
    Initial delay in milliseconds before showing the message prompt.
    void
    Kind of stream to use such as System.in, System.out, a file, or a http url.
    void
    setPromptDelay(long promptDelay)
    Optional delay in milliseconds before showing the message prompt.
    void
    setPromptMessage(String promptMessage)
    Message prompt to use when reading from stream:in; for example, you could set this to Enter a command:
    void
    setReadLine(boolean readLine)
    Whether to read the input stream in line mode (terminate by line breaks).
    void
    setReadTimeout(int readTimeout)
    Sets the read timeout to a specified timeout, in milliseconds.
    void
    setRetry(boolean retry)
    Will retry opening the stream if it's overwritten, somewhat like tail --retry
    void
    setScanStream(boolean scanStream)
    To be used for continuously reading a stream such as the unix tail command.
    void
    setScanStreamDelay(long scanStreamDelay)
    Delay in milliseconds between read attempts when using scanStream.

    Methods inherited from class org.apache.camel.support.DefaultEndpoint

    configureConsumer, configureExchange, configurePollingConsumer, configureProperties, createAsyncProducer, createEndpointUri, createExchange, createExchange, createPollingConsumer, doInit, equals, getCamelContext, getComponent, getEndpointKey, getEndpointUri, getExceptionHandler, getExchangePattern, getId, getPollingConsumerBlockTimeout, getPollingConsumerQueueSize, hashCode, isAutowiredEnabled, isBridgeErrorHandler, isLazyStartProducer, isLenientProperties, isPollingConsumerBlockWhenFull, isPollingConsumerCopy, isSingleton, setAutowiredEnabled, setBridgeErrorHandler, setCamelContext, setComponent, setEndpointUri, setEndpointUriIfNotSpecified, setExceptionHandler, setExchangePattern, setLazyStartProducer, setPollingConsumerBlockTimeout, setPollingConsumerBlockWhenFull, setPollingConsumerCopy, setPollingConsumerQueueSize, setProperties, toString

    Methods inherited from class org.apache.camel.support.service.BaseService

    build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doStop, 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

    Methods inherited from interface org.apache.camel.ComponentAware

    getComponent

    Methods inherited from interface org.apache.camel.Endpoint

    getEndpointBaseUri, isSingletonProducer

    Methods inherited from interface org.apache.camel.Service

    build, close, init, start, stop

    Methods inherited from interface org.apache.camel.ShutdownableService

    shutdown

    Methods inherited from interface org.apache.camel.StatefulService

    getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending

    Methods inherited from interface org.apache.camel.SuspendableService

    isSuspended, resume, suspend
  • Constructor Details

    • StreamEndpoint

      public StreamEndpoint(String endpointUri, org.apache.camel.Component component) throws Exception
      Throws:
      Exception
  • Method Details

    • createConsumer

      public org.apache.camel.Consumer createConsumer(org.apache.camel.Processor processor) throws Exception
      Throws:
      Exception
    • createProducer

      public org.apache.camel.Producer createProducer() throws Exception
      Throws:
      Exception
    • getKind

      public String getKind()
    • setKind

      public void setKind(String kind)
      Kind of stream to use such as System.in, System.out, a file, or a http url.
    • getFileName

      public String getFileName()
    • setFileName

      public void setFileName(String fileName)
      When using the stream:file URI format, this option specifies the filename to stream to/from.
    • getHttpUrl

      public String getHttpUrl()
    • setHttpUrl

      public void setHttpUrl(String httpUrl)
      When using stream:http format, this option specifies the http url to stream from.
    • getHttpHeaders

      public String getHttpHeaders()
    • setHttpHeaders

      public void setHttpHeaders(String httpHeaders)
      When using stream:http format, this option specifies optional http headers, such as Accept: application/json. Multiple headers can be separated by comma.
    • getDelay

      public long getDelay()
    • setDelay

      public void setDelay(long delay)
      Initial delay in milliseconds before producing the stream.
    • getEncoding

      public String getEncoding()
    • setEncoding

      public void setEncoding(String encoding)
      You can configure the encoding (is a charset name) to use text-based streams (for example, message body is a String object). If not provided, Camel uses the JVM default Charset.
    • getPromptMessage

      public String getPromptMessage()
    • setPromptMessage

      public void setPromptMessage(String promptMessage)
      Message prompt to use when reading from stream:in; for example, you could set this to Enter a command:
    • getPromptDelay

      public long getPromptDelay()
    • setPromptDelay

      public void setPromptDelay(long promptDelay)
      Optional delay in milliseconds before showing the message prompt.
    • getInitialPromptDelay

      public long getInitialPromptDelay()
    • setInitialPromptDelay

      public void setInitialPromptDelay(long initialPromptDelay)
      Initial delay in milliseconds before showing the message prompt. This delay occurs only once. Can be used during system startup to avoid message prompts being written while other logging is done to the system out.
    • isScanStream

      public boolean isScanStream()
    • setScanStream

      public void setScanStream(boolean scanStream)
      To be used for continuously reading a stream such as the unix tail command.
    • getGroupStrategy

      public GroupStrategy getGroupStrategy()
    • setGroupStrategy

      public void setGroupStrategy(GroupStrategy strategy)
      Allows to use a custom GroupStrategy to control how to group lines.
    • isRetry

      public boolean isRetry()
    • setRetry

      public void setRetry(boolean retry)
      Will retry opening the stream if it's overwritten, somewhat like tail --retry

      If reading from files then you should also enable the fileWatcher option, to make it work reliable.

    • isFileWatcher

      public boolean isFileWatcher()
    • setFileWatcher

      public void setFileWatcher(boolean fileWatcher)
      To use JVM file watcher to listen for file change events to support re-loading files that may be overwritten, somewhat like tail --retry
    • isCloseOnDone

      public boolean isCloseOnDone()
    • setCloseOnDone

      public void setCloseOnDone(boolean closeOnDone)
      This option is used in combination with Splitter and streaming to the same file. The idea is to keep the stream open and only close when the Splitter is done, to improve performance. Mind this requires that you only stream to the same file, and not 2 or more files.
    • getScanStreamDelay

      public long getScanStreamDelay()
    • setScanStreamDelay

      public void setScanStreamDelay(long scanStreamDelay)
      Delay in milliseconds between read attempts when using scanStream.
    • getGroupLines

      public int getGroupLines()
    • setGroupLines

      public void setGroupLines(int groupLines)
      To group X number of lines in the consumer. For example to group 10 lines and therefore only spit out an Exchange with 10 lines, instead of 1 Exchange per line.
    • isReadLine

      public boolean isReadLine()
    • setReadLine

      public void setReadLine(boolean readLine)
      Whether to read the input stream in line mode (terminate by line breaks). Setting this to false, will instead read the entire stream until EOL.
    • getAutoCloseCount

      public int getAutoCloseCount()
    • setAutoCloseCount

      public void setAutoCloseCount(int autoCloseCount)
      Number of messages to process before closing stream on Producer side. Never close stream by default (only when Producer is stopped). If more messages are sent, the stream is reopened for another autoCloseCount batch.
    • isAppendNewLine

      public boolean isAppendNewLine()
    • setAppendNewLine

      public void setAppendNewLine(boolean appendNewLine)
      Whether to append a new line character at end of output.
    • getCharset

      public Charset getCharset()
    • getReadTimeout

      public int getReadTimeout()
    • setReadTimeout

      public void setReadTimeout(int readTimeout)
      Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.apache.camel.support.service.BaseService
      Throws:
      Exception