Skip to content

Instantly share code, notes, and snippets.

@greghelton
Created May 23, 2026 14:04
Show Gist options
  • Select an option

  • Save greghelton/e9c3022b2e35d95eac1f11f8aac59530 to your computer and use it in GitHub Desktop.

Select an option

Save greghelton/e9c3022b2e35d95eac1f11f8aac59530 to your computer and use it in GitHub Desktop.
jt400.jar is very cool. I had chatgpt write an application that uses AS400 DTAQs. The AS400 often responds to requests from other application tiers but with DTAQs, it can send a request out to the web. Here, the request would be managed or acted on by additional Kotlin code.
import com.ibm.as400.access.AS400
import com.ibm.as400.access.DataQueue
import com.ibm.as400.access.DataQueueEntry
import com.ibm.as400.access.KeyedDataQueue
import java.nio.charset.Charset
fun main() {
// Connect to IBM i
val system = AS400(
"myibmi.company.com",
"MYUSER",
"MYPASSWORD"
)
// FIFO data queue (source)
val fifoQueuePath =
"/QSYS.LIB/MYLIB.LIB/INQUEUE.DTAQ"
// Keyed data queue (target)
val keyedQueuePath =
"/QSYS.LIB/MYLIB.LIB/OUTQUEUE.DTAQ"
val fifoQueue = DataQueue(system, fifoQueuePath)
val keyedQueue = KeyedDataQueue(system, keyedQueuePath)
try {
println("Waiting for message from FIFO queue...")
// Blocking read
val entry: DataQueueEntry = fifoQueue.read()
val rawData: ByteArray = entry.data
val message =
String(rawData, Charset.forName("IBM037")).trim()
println("Received: $message")
/*
Example message format:
CUST1001|Invoice 44321
Key = CUST1001
Payload = Invoice 44321
*/
val parts = message.split("|")
if (parts.size < 2) {
throw IllegalArgumentException(
"Invalid message format"
)
}
val key = parts[0]
val payload = parts[1]
println("Key: $key")
println("Payload: $payload")
// Convert key/data to bytes
val keyBytes =
key.toByteArray(Charset.forName("IBM037"))
val payloadBytes =
payload.toByteArray(Charset.forName("IBM037"))
// Write to keyed data queue
keyedQueue.write(
keyBytes,
payloadBytes
)
println("Message written to keyed queue")
} finally {
// Disconnect data queue service
system.disconnectService(AS400.DATAQUEUE)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment