[[jt400-component]]
= JT400 Component
:docTitle: JT400
:artifactId: camel-jt400
:description: Exchanges messages with an IBM i system using data queues, message queues, or program call. IBM i is the replacement for AS/400 and iSeries servers.
:since: 1.5
:supportLevel: Stable
:component-header: Both producer and consumer are supported

*Since Camel {since}*

*{component-header}*

The JT400 component allows you to exchange messages with an IBM i system
using data queues, message queues, or program call. IBM i is the
replacement for AS/400 and iSeries servers.

Maven users will need to add the following dependency to their `pom.xml`
for this component:

[source,xml]
------------------------------------------------------------
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jt400</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
------------------------------------------------------------

== URI format

To send or receive data from a data queue

[source,java]
----------------------------------------------------------------------
jt400://user:password@system/QSYS.LIB/LIBRARY.LIB/QUEUE.DTAQ[?options]
----------------------------------------------------------------------

To send or receive messages from a message queue

[source,java]
----------------------------------------------------------------------
jt400://user:password@system/QSYS.LIB/LIBRARY.LIB/QUEUE.MSGQ[?options]
----------------------------------------------------------------------

To call remote program

[source,java]
-----------------------------------------------------------------------
jt400://user:password@system/QSYS.LIB/LIBRARY.LIB/program.PGM[?options]
-----------------------------------------------------------------------

You can append query options to the URI in the following format,
`?option=value&option=value&...`

== JT400 options

// component options: START
The JT400 component supports 4 options, which are listed below.



[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
| *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean
| *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
| *connectionPool* (advanced) | Default connection pool used by the component. Note that this pool is lazily initialized. This is because in a scenario where the user always provides a pool, it would be wasteful for Camel to initialize and keep an idle pool. |  | AS400ConnectionPool
|===
// component options: END


// endpoint options: START
The JT400 endpoint is configured using URI syntax:

----
jt400:userID:password/systemName/objectPath.type
----

with the following path and query parameters:

=== Path Parameters (5 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *userID* | *Required* Returns the ID of the IBM i user. |  | String
| *password* | *Required* Returns the password of the IBM i user. |  | String
| *systemName* | *Required* Returns the name of the IBM i system. |  | String
| *objectPath* | *Required* Returns the fully qualified integrated file system path name of the target object of this endpoint. |  | String
| *type* | *Required* Whether to work with data queues or remote program call. The value can be one of: DTAQ, PGM, SRVPGM, MSGQ |  | Jt400Type
|===


=== Query Parameters (34 parameters):


[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
| *ccsid* (common) | Sets the CCSID to use for the connection with the IBM i system. |  | int
| *format* (common) | Sets the data format for sending messages. The value can be one of: text, binary | text | Format
| *guiAvailable* (common) | Sets whether IBM i prompting is enabled in the environment running Camel. | false | boolean
| *keyed* (common) | Whether to use keyed or non-keyed data queues. | false | boolean
| *searchKey* (common) | Search key for keyed data queues. |  | String
| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
| *messageAction* (consumer) | Action to be taken on messages when read from a message queue. Messages can be marked as old (OLD), removed from the queue (REMOVE), or neither (SAME). The value can be one of: OLD, REMOVE, SAME | OLD | MessageAction
| *readTimeout* (consumer) | Timeout in millis the consumer will wait while trying to read a new message of the data queue. | 30000 | int
| *searchType* (consumer) | Search type such as EQ for equal etc. The value can be one of: EQ, NE, LT, LE, GT, GE | EQ | SearchType
| *sendEmptyMessageWhenIdle* (consumer) | If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean
| *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
| *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. The value can be one of: InOnly, InOut, InOptionalOut |  | ExchangePattern
| *pollStrategy* (consumer) | A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. |  | PollingConsumerPollStrategy
| *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean
| *outputFieldsIdxArray* (producer) | Specifies which fields (program parameters) are output parameters. |  | Integer[]
| *outputFieldsLengthArray* (producer) | Specifies the fields (program parameters) length as in the IBM i program definition. |  | Integer[]
| *procedureName* (producer) | Procedure name from a service program to call |  | String
| *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
| *backoffErrorThreshold* (scheduler) | The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. |  | int
| *backoffIdleThreshold* (scheduler) | The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. |  | int
| *backoffMultiplier* (scheduler) | To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. |  | int
| *delay* (scheduler) | Milliseconds before the next poll. | 500 | long
| *greedy* (scheduler) | If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean
| *initialDelay* (scheduler) | Milliseconds before the first poll starts. | 1000 | long
| *repeatCount* (scheduler) | Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long
| *runLoggingLevel* (scheduler) | The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. The value can be one of: TRACE, DEBUG, INFO, WARN, ERROR, OFF | TRACE | LoggingLevel
| *scheduledExecutorService* (scheduler) | Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. |  | ScheduledExecutorService
| *scheduler* (scheduler) | To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler | none | Object
| *schedulerProperties* (scheduler) | To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. |  | Map
| *startScheduler* (scheduler) | Whether the scheduler should be auto started. | true | boolean
| *timeUnit* (scheduler) | Time unit for initialDelay and delay options. The value can be one of: NANOSECONDS, MICROSECONDS, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS | MILLISECONDS | TimeUnit
| *useFixedDelay* (scheduler) | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean
| *secured* (security) | Whether connections to IBM i are secured with SSL. | false | boolean
|===
// endpoint options: END



== Usage

When configured as a data queue consumer endpoint, the endpoint will poll a data
queue on a remote system. For every entry on the data queue, a new
`Exchange` is sent with the entry's data in the _In_ message's body,
formatted either as a `String` or a `byte[]`, depending on the format.
For a provider endpoint, the _In_ message body contents will be put on
the data queue as either raw bytes or text.

When configured as a message queue consumer endpoint, the endpoint will poll
a message queue on a remote system. For every entry on the queue, a new
`Exchange` is sent with the entry's data in the _In_ message's body. The
data is always formatted as a `String`. Note that only new messages will
be processed. That is, any existing messages on the queue that have already
been handled by another program will not be processed by this endpoint.

For a data queue provider endpoint, the _In_ message body contents will be
put on the data queue as either raw bytes or text.

For a message queue provider endpoint, the _In_ message body contents are
presumed to be text and sent to the queue as an informational message.
Inquiry messages or messages requiring a message ID are not supported.

== Connection pool

*Since Camel 2.10*

You can explicit configure a connection pool on the Jt400Component, or as an uri option
on the endpoint.

=== Remote program call (*Camel 2.7*)

This endpoint expects the input to be either a String array or byte[]
array (depending on format) and handles all the CCSID handling through
the native jt400 library mechanisms. A parameter can be _omitted_ by
passing null as the value in its position (the remote program has to
support it). After the program execution the endpoint returns either a
String array or byte[] array with the values as they were returned by
the program (the input only parameters will contain the same data as the
beginning of the invocation). This endpoint does not implement a provider endpoint!

== Message headers

=== Consumer headers when consuming from data queues

The following headers are potentially available. If the values could not
be determined, the headers will not be set
[width="100%",cols="2m,2m,1m,5",options="header"]
|===
| Header constant                          | Header value                      | Type    | Description
| Jt400Endpoint.SENDER_INFORMATION         | "SENDER_INFORMATION"              | String  | Returns the sender information for this data queue entry, or an empty string if not available
|===

=== Consumer headers when consuming from message queues

The following headers are potentially available. If the values could not
be determined, the headers will not be set
[width="100%",cols="2m,2m,1m,5",options="header"]
|===
| Header constant                          | Header value                      | Type    | Description
| Jt400Endpoint.MESSAGE_ID                 | "CamelJt400MessageID"             | String  | The message identifier
| Jt400Endpoint.MESSAGE_FILE               | "CamelJt400MessageFile"           | String  | The message file name
| Jt400Endpoint.MESSAGE_TYPE               | "CamelJt400MessageType"           | Integer | The message type (corresponds to constants defined in the AS400Message class)
| Jt400Endpoint.SENDER_INFORMATION         | "SENDER_INFORMATION"              | String  | The job identifier of the sending job
|===

== Example

In the snippet below, the data for an exchange sent to the
`direct:george` endpoint will be put in the data queue `PENNYLANE` in
library `BEATLES` on a system named `LIVERPOOL`.  +
 Another user connects to the same data queue to receive the information
from the data queue and forward it to the `mock:ringo` endpoint.

[source,java]
-------------------------------------------------------------------------------------------------------
public class Jt400RouteBuilder extends RouteBuilder {
    @Override
    public void configure() throws Exception {
       from("direct:george").to("jt400://GEORGE:EGROEG@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ");
       from("jt400://RINGO:OGNIR@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ").to("mock:ringo");
    }
}
-------------------------------------------------------------------------------------------------------

=== Remote program call example

In the snippet below, the data Exchange sent to the direct:work endpoint
will contain three string that will be used as the arguments for the
program “compute” in the library “assets”. This program will write the
output values in the 2nd and 3rd parameters. All the parameters will be
sent to the direct:play endpoint.

[source,java]
---------------------------------------------------------------------------------------------------------------------------------------------------------
public class Jt400RouteBuilder extends RouteBuilder {
    @Override
    public void configure() throws Exception {
       from("direct:work").to("jt400://GRUPO:ATWORK@server/QSYS.LIB/assets.LIB/compute.PGM?fieldsLength=10,10,512&ouputFieldsIdx=2,3").to(“direct:play”);
    }
}
---------------------------------------------------------------------------------------------------------------------------------------------------------

=== Writing to keyed data queues

[source,java]
------------------------------------------------------------------------
from("jms:queue:input")
.to("jt400://username:password@system/lib.lib/MSGINDQ.DTAQ?keyed=true");
------------------------------------------------------------------------

=== Reading from keyed data queues

[source,java]
-------------------------------------------------------------------------------------------------------
from("jt400://username:password@system/lib.lib/MSGOUTDQ.DTAQ?keyed=true&searchKey=MYKEY&searchType=GE")
.to("jms:queue:output");
-------------------------------------------------------------------------------------------------------

=== Writing to message queues

[source,java]
------------------------------------------------------------------------
from("jms:queue:input")
.to("jt400://username:password@system/lib.lib/MSGINQ.MSGQ");
------------------------------------------------------------------------

=== Reading from a message queue

[source,java]
-------------------------------------------------------------------------------------------------------
from("jt400://username:password@system/lib.lib/MSGOUTQ.DTAQ")
.to("jms:queue:output");
-------------------------------------------------------------------------------------------------------


include::camel-spring-boot::page$jt400-starter.adoc[]
