Skip to content

Latest commit

 

History

History
224 lines (174 loc) · 9.08 KB

jt400-component.adoc

File metadata and controls

224 lines (174 loc) · 9.08 KB

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 program

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

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[], 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). 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. This endpoint does not implement a provider endpoint!

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.

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");
    }
}

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.

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");
    }
}

In this example, the camel route will call the QUSRTVUS API to retrieve 16 bytes from data area "MYUSRSPACE" in the "MYLIB" library.

public class Jt400RouteBuilder extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        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

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

Reading from keyed data queues

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

Writing to message queues

from("jms:queue:input")
.to("jt400://username:password@system/lib.lib/MSGINQ.MSGQ");

Reading from a message queue

from("jt400://username:password@system/lib.lib/MSGOUTQ.MSGQ")
.to("jms:queue:output");

Replying to an inquiry message on a message queue

from("jt400://username:password@localhost/qsys.lib/qusrsys.lib/myq.msgq?sendingReply=true")
.choice()
    .when(header(Jt400Constants.MESSAGE_TYPE).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");

spring-boot:partial$starter.adoc