Camel Components

JT400

Since Camel 1.5

Both producer and consumer are supported

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:

<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

jt400://user:password@system/QSYS.LIB/library.LIB/queue.DTAQ[?options]

To send or receive messages from a message queue

jt400://user:password@system/QSYS.LIB/library.LIB/queue.MSGQ[?options]

To call a program

jt400://user:password@system/QSYS.LIB/library.LIB/program.PGM[?options]

To call a service program

jt400://user:password@system/QSYS.LIB/library.LIB/program.SRVPGM[?options]

The suffix of the object path (.DTAQ, .MSGQ, .PGM or .SRVPGM) selects what the endpoint works with.

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The JT400 component supports the following options which are listed below.

Name Description Default Type

bridgeErrorHandler (consumer)

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. 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

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

connectionPool (advanced)

The AS400ConnectionPool for the connections to the IBM i system. An endpoint can use another pool with the connectionPool URI parameter, a reference to a bean in the registry such as #myPool. When not set, the component creates a default pool on first use. The component closes this pool when it shuts down.

AS400ConnectionPool

healthCheckConsumerEnabled (health)

Used for enabling or disabling all consumer based health checks from this component.

true

boolean

healthCheckProducerEnabled (health)

Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true.

true

boolean

Endpoint Options

The JT400 endpoint is configured using URI syntax:

jt400:userID:password@systemName/objectPath

With the following path and query parameters:

Path Parameters

Name Description Default Type

userID (security)

Required The user profile to sign on to the IBM i system with.

String

password (security)

Required The password of the user profile.

String

systemName (security)

Required The host name or IP address of the IBM i system.

String

objectPath (common)

Required The integrated file system path of the object on the IBM i system, such as /QSYS.LIB/MYLIB.LIB/MYQUEUE.DTAQ. The suffix of the object name (not case-sensitive) selects what the endpoint works with: .DTAQ a data queue, .MSGQ a message queue, .PGM a program call and .SRVPGM a service program call. A program or service program call is a producer only.

String

Query Parameters

Name Description Default Type

ccsid (common)

The CCSID that the connection to the IBM i system converts text with: the messages of a message queue, the text parameters of a program call and, unless dataQueueCcsid is set, the text entries and keys of a data queue. When not set, the CCSID of the user profile on the IBM i system is used.

int

format (common)

The data format of the entries and keys of a data queue, and of the output parameters of a program call: text for a String, binary for a byte array. A message queue always uses text.

Enum values:

  • text

  • binary

text

Format

guiAvailable (common)

Whether the IBM Toolbox for Java may show GUI prompts when it signs on to the IBM i system, such as a sign-on dialog, a change password dialog or an error dialog. When false, an error or missing sign-on information causes an exception instead.

false

boolean

keyed (common)

Whether the data queue is a keyed data queue (KeyedDataQueue) instead of a sequential data queue (DataQueue). The producer takes the key of each entry from the CamelJt400Key header, and the consumer reads the entries whose key matches searchKey and searchType.

false

boolean

searchKey (common)

The key that the consumer of a keyed data queue compares the key of each entry with, using searchType. Required for the consumer of a keyed data queue. The key is converted with the CCSID of the data queue (also with format binary) and padded with zero bytes to the key length of the data queue.

String

dataQueueCcsid (consumer)

The CCSID that the text entries and the keys of the data queue are converted with, when writing and when reading. When not set, the CCSID of the connection is used (see ccsid).

int

messageAction (consumer)

What happens to a message on the message queue when the consumer receives it: OLD keeps it and marks it as old, REMOVE removes it, and SAME keeps it without changing its new or old designation. With SAME the consumer remembers the key of the message it received, and receives the message after it on the next poll.

Enum values:

  • OLD

  • REMOVE

  • SAME

OLD

MessageAction

readTimeout (consumer)

How long, in milliseconds, each poll of the consumer waits for an entry on the data queue or a message on the message queue. The IBM Toolbox for Java waits in whole seconds, so the value is rounded down to seconds: a value below 1000 does not wait, and a negative value waits until an entry or message arrives.

30000

int

searchType (consumer)

How the consumer of a keyed data queue compares the key of each entry with searchKey: EQ (equal), NE (not equal), LT (less than), LE (less than or equal), GT (greater than) or GE (greater than or equal).

Enum values:

  • 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

sendingReply (consumer)

Whether the consumer sets the CamelJt400MessageReplyToKey header for the inquiry messages it receives. When such a message is then sent to a producer of the same message queue, the producer replies to the inquiry message with the message body instead of sending a new message. The reply needs a valid message key, so it does not work with messageAction REMOVE.

true

boolean

bridgeErrorHandler (consumer (advanced))

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. 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

exceptionHandler (consumer (advanced))

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 (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

ExchangePattern

pollStrategy (consumer (advanced))

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

fieldsLength (producer)

The length in bytes of each program parameter as in the IBM i program definition, as a comma-separated list in parameter order. A length is needed for each output parameter and for each text or byte array input parameter; an int input parameter uses 4 bytes and a long input parameter 8 bytes.

String

outputFieldsIdx (producer)

The 0-based indexes of the program parameters that are output parameters, as a comma-separated list in any order. An output parameter whose value in the message body is not null is also an input parameter. When not set, all parameters are input parameters.

String

procedureName (producer)

The name of the procedure to call in the service program, when the object path ends with .SRVPGM. The name is case-sensitive. The return value of the procedure is not received.

String

lazyStartProducer (producer (advanced))

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

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

healthCheckMaxPollDuration (scheduler)

How long a poll may run before the health check of the consumer reports DOWN. The health check is otherwise based on the polls that are done, so it stays UP while a poll hangs, for example on a read without timeout from a connection that went silent. A poll includes routing the messages it polled, so set this above the longest poll you expect. The poll is not interrupted. The value is in millis (not affected by timeUnit). The default 0 turns this off.

0

long

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.

Enum values:

  • 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. This is a multi-value option with prefix: scheduler.

Map

startScheduler (scheduler)

Whether the scheduler should be auto started.

true

boolean

timeUnit (scheduler)

Time unit for initialDelay and delay options.

Enum values:

  • 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 to connect to the IBM i system with SSL/TLS, using a secure connection (SecureAS400) from the AS400ConnectionPool.

false

boolean

Message Headers

The JT400 component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelJt400SenderInformation (consumer)

Constant: SENDER_INFORMATION

For a data queue, the sender information of the entry, or an empty string when the data queue does not save sender information. For a message queue, the job that sent the message, as job number/user/job name.

String

CamelJt400Key (common)

Constant: KEY

The key of a keyed data queue entry: a String, or a byte array with format binary. The consumer sets it to the key of the entry it read, and the producer writes the entry with this key (required for a keyed data queue).

String or byte[]

CamelJt400Message (consumer)

Constant: MESSAGE

The received message, as an IBM Toolbox for Java QueuedMessage.

QueuedMessage

CamelJt400MessageID (consumer)

Constant: MESSAGE_ID

The message identifier, such as CPF9898, when the message has one.

String

CamelJt400MessageFile (consumer)

Constant: MESSAGE_FILE

The name of the message file of the message, when the message has one.

String

CamelJt400MessageType (consumer)

Constant: MESSAGE_TYPE

The message type, as one of the message type constants of the AS400Message class, such as AS400Message.INQUIRY.

Integer

CamelJt400MessageSeverity (consumer)

Constant: MESSAGE_SEVERITY

The message severity, from 0 to 99, or -1 when it is not set.

Integer

CamelJt400MessageDefaultReply (consumer)

Constant: MESSAGE_DFT_RPY

The default reply of an inquiry message, when it has one.

String

CamelJt400MessageReplyToKey (common)

Constant: MESSAGE_REPLYTO_KEY

The key of an inquiry message to reply to. The consumer sets it for each inquiry message it receives when sendingReply is true. When the producer gets this header and the message body is not empty, it replies to the inquiry message with this key, with the body as reply text, instead of sending a new informational message.

byte[]

Message Body

The message body at each side of the JT400 component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Consumer

text

The data queue entry as a String, or a byte array with format=binary; a message queue (.MSGQ) always gives the message text.

  • With format=binary: bytes

  • With sendEmptyMessageWhenIdle=true: text, bytes or null

Not known when objectPath is set.

Producer input

any

A queue writes the body converted to a String, or to a byte array with format=binary (text, bytes or a stream). A program call (.PGM, .SRVPGM) needs an Object[] of the parameters (a List is converted to an array).

Not known when objectPath or format is set.

Producer output

unchanged

Unchanged for a queue. A program call sets an Object[] of the parameters, the output ones replaced by what the program returned: Strings, or byte arrays with format=binary.

Not known when objectPath is set.

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Usage

When configured as a data queue consumer endpoint, the endpoint will poll a data queue on an IBM i 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 data queue 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 an IBM i 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, this endpoint will not process any existing messages on the queue that have already been handled by another program.

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

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

Program call

This endpoint expects the input to be an Object[] (a List is converted to an array), whose object types are int, long, CharSequence (such as String), or byte[]. All other data types in the input array will be converted to String. For character inputs, CCSID handling is performed through the native jt400 library mechanisms. A parameter can be omitted by passing null as the value in its position (the program has to support it). The outputFieldsIdx option lists the output parameters (in any order); when it is not set, all parameters are input-only. The fieldsLength option gives the length of each parameter. A length is needed for output parameters and for text and byte[] input parameters, but not for int and long inputs. After the program execution, the endpoint returns an Object[] in the message body. Depending on format, the returned array will be populated with byte[] or String objects representing the values as they were returned by the program. Input-only parameters will contain the same data as the beginning of the invocation. A program call endpoint can only be used as a producer.

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.

  • Java

  • XML

  • YAML

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");
<route>
  <from uri="direct:george"/>
  <to uri="jt400://GEORGE:EGROEG@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ"/>
</route>

<route>
  <from uri="jt400://RINGO:OGNIR@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ"/>
  <to uri="mock:ringo"/>
</route>
- route:
    from:
      uri: direct:george
      steps:
        - to:
            uri: jt400://GEORGE:EGROEG@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ

- route:
    from:
      uri: jt400://RINGO:OGNIR@LIVERPOOL/QSYS.LIB/BEATLES.LIB/PENNYLANE.DTAQ
      steps:
        - to:
            uri: mock:ringo

Program call examples

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

  • Java

  • XML

  • YAML

from("direct:work").to("jt400://GRUPO:ATWORK@server/QSYS.LIB/assets.LIB/compute.PGM?fieldsLength=10,10,512&outputFieldsIdx=1,2").to("direct:play");
<route>
  <from uri="direct:work"/>
  <to uri="jt400://GRUPO:ATWORK@server/QSYS.LIB/assets.LIB/compute.PGM?fieldsLength=10,10,512&amp;outputFieldsIdx=1,2"/>
  <to uri="direct:play"/>
</route>
- route:
    from:
      uri: direct:work
      steps:
        - to:
            uri: jt400://GRUPO:ATWORK@server/QSYS.LIB/assets.LIB/compute.PGM
            parameters:
              fieldsLength: "10,10,512"
              outputFieldsIdx: "1,2"
        - to:
            uri: direct:play

In this example, the camel route will call the QUSRTVUS API to retrieve 16 bytes from the user space “MYUSRSPACE” in the “MYLIB” library.

Java-only: uses lambda Processor to set program call parameters
from("timer://foo?period=60000")
    .process( exchange -> {
        String usrSpc = "MYUSRSPACEMYLIB     ";
        Object[] parms = new Object[] {
            usrSpc, // Qualified user space name
            1,      // starting position
            16,     // length of data
            "" // output
        };
        exchange.getIn().setBody(parms);
    })
    .to("jt400://*CURRENT:*CURRENT@localhost/qsys.lib/QUSRTVUS.PGM?fieldsLength=20,4,4,16&outputFieldsIdx=3")
    .setBody(simple("${body[3]}"))
    .to("direct:foo");

Writing to keyed data queues

  • Java

  • XML

  • YAML

from("jms:queue:input")
    .to("jt400://username:password@system/lib.lib/MSGINDQ.DTAQ?keyed=true");
<route>
    <from uri="jms:queue:input"/>
    <to uri="jt400://username:password@system/lib.lib/MSGINDQ.DTAQ?keyed=true"/>
</route>
- route:
    from:
      uri: jms:queue:input
      steps:
        - to:
            uri: jt400://username:password@system/lib.lib/MSGINDQ.DTAQ
            parameters:
              keyed: true

Reading from keyed data queues

  • Java

  • XML

  • YAML

from("jt400://username:password@system/lib.lib/MSGOUTDQ.DTAQ?keyed=true&searchKey=MYKEY&searchType=GE")
    .to("jms:queue:output");
<route>
    <from uri="jt400://username:password@system/lib.lib/MSGOUTDQ.DTAQ?keyed=true&amp;searchKey=MYKEY&amp;searchType=GE"/>
    <to uri="jms:queue:output"/>
</route>
- route:
    from:
      uri: jt400://username:password@system/lib.lib/MSGOUTDQ.DTAQ
      parameters:
        keyed: true
        searchKey: MYKEY
        searchType: GE
      steps:
        - to:
            uri: jms:queue:output

Writing to message queues

  • Java

  • XML

  • YAML

from("jms:queue:input")
    .to("jt400://username:password@system/lib.lib/MSGINQ.MSGQ");
<route>
    <from uri="jms:queue:input"/>
    <to uri="jt400://username:password@system/lib.lib/MSGINQ.MSGQ"/>
</route>
- route:
    from:
      uri: jms:queue:input
      steps:
        - to:
            uri: jt400://username:password@system/lib.lib/MSGINQ.MSGQ

Reading from a message queue

  • Java

  • XML

  • YAML

from("jt400://username:password@system/lib.lib/MSGOUTQ.MSGQ")
    .to("jms:queue:output");
<route>
    <from uri="jt400://username:password@system/lib.lib/MSGOUTQ.MSGQ"/>
    <to uri="jms:queue:output"/>
</route>
- route:
    from:
      uri: jt400://username:password@system/lib.lib/MSGOUTQ.MSGQ
      steps:
        - to:
            uri: jms:queue:output

Replying to an inquiry message on a message queue

Java-only: uses Java constants, lambda expression, and choice with header() predicate
from("jt400://username:password@localhost/qsys.lib/qusrsys.lib/myq.msgq?sendingReply=true")
.choice()
    .when(header("CamelJt400MessageType").isEqualTo(AS400Message.INQUIRY))
        .process((exchange) -> {
            String reply = // insert reply logic here
            exchange.getIn().setBody(reply);
        })
        .to("jt400://username:password@localhost/qsys.lib/qusrsys.lib/myq.msgq");