JReactive-8583

repository·main·Indexed 43 days ago

https://github.com/kpavlov/jreactive-8583

A free, Netty-based ISO8583 connector for the JDK providing asynchronous client and server endpoints for ISO8583 messaging. It utilizes the j8583 library for encoding and decoding and supports custom message logging, TCP/IP transport framing, and configurable message factories.

Tokens
1.3K
Snippets
3
Records
5
Agent score
6%

What's inside JReactive-8583

  1. Understand the ISO8583 TCP/IP Transport mechanism

    main

    The library uses a single TCP/IP session for bi-directional data transfer. The continuous stream is split into frames, where each frame contains one ISO8583 message.

    A frame structure consists of:

    1. N-byte length header: Indicates the length of the following message (usually 2 bytes). The high byte is transmitted first, followed by the low byte.
    2. M-byte message body: The actual ISO8583 message.
  2. Install JReactive-8583 via Maven

    main

    Add the netty-iso8583 dependency to your Maven pom.xml to use the ISO8583 client and server capabilities.

    <dependencies>
        <dependency>
            <groupId>com.github.kpavlov.jreactive8583</groupId>
            <artifactId>netty-iso8583</artifactId>
            <version>${LATEST_VERSION}</version>
        </dependency>
    </dependencies>
  3. Create and use an ISO-8583 Server

    main

    To implement an ISO8583 server, follow these steps:

    1. Create a J8583MessageFactory specifying the ConfigParser, ISO8583Version, and MessageOrigin (e.g., ACQUIRER, ISSUER, or OTHER).
    2. Instantiate Iso8583Server with the port and the factory.
    3. Register an IsoMessageListener to handle incoming IsoMessage objects.
    4. Configure the server (optional) using server.getConfiguration().
    5. Call server.init() to prepare the server.
    6. Call server.start() to begin accepting client connections.
    7. Call server.shutdown() when finished.
    var messageFactory = new J8583MessageFactory<>(ConfigParser.createDefault(), ISO8583Version.V1987, MessageOrigin.ACQUIRER);
    Iso8583Server<IsoMessage> server = new Iso8583Server<>(port, messageFactory);
    
    server.addMessageListener(new IsoMessageListener<IsoMessage>() {
        @Override
        public void onMessage(IsoMessage message) {
            // Handle incoming message
        }
    });
    
    server.getConfiguration().replyOnError(true);
    server.init();
    
    server.start();
    if (server.isStarted()) {
        // Server is running
    }
    
    server.shutdown();
  4. Create and use an ISO-8583 Client

    main

    To implement an ISO8583 client, follow these steps:

    1. Create a J8583MessageFactory specifying the ISO8583Version and MessageOrigin (e.g., ACQUIRER, ISSUER, or OTHER).
    2. Instantiate Iso8583Client with the factory.
    3. Register an IsoMessageListener to handle incoming IsoMessage objects.
    4. Configure the client (optional) using client.getConfiguration().
    5. Call client.init() to prepare the client.
    6. Call client.connect(host, port) to establish the connection. Automatic reconnection is enabled by default.
    7. Use sendAsync(message), send(message), or send(message, timeout, unit) to transmit messages.
    8. Call client.shutdown() when finished.
    var messageFactory = new J8583MessageFactory<>(ISO8583Version.V1987, MessageOrigin.OTHER);
    Iso8583Client<IsoMessage> client = new Iso8583Client<>(messageFactory);
    
    client.addMessageListener(new IsoMessageListener<IsoMessage>() {
        @Override
        public void onMessage(IsoMessage message) {
            // Handle incoming message
        }
    });
    
    client.getConfiguration().replyOnError(true);
    client.init();
    
    client.connect(host, port);
    if (client.isConnected()) {
        IsoMessage message = messageFactory.newMessage(...);
        client.sendAsync(message);
        // or
        client.send(message);
        // or
        client.send(message, 1, TimeUnit.SECONDS);
    }
    
    client.shutdown();
  5. Configure ISO-8583 message logging

    main

    JReactive-8583 provides an IsoMessageLoggingHandler to log ISO8583 messages. Note that logging is disabled by default.

    You can customize logging via ClientConfiguration or ServerConfiguration to:

    • Enable or disable message logging.
    • Enable or disable printing of sensitive information (like PAN).
    • Customize which fields are masked in logs.
    • Enable or disable printing of field descriptions.
    • Customize the TCP frame length field length.
    • Customize the ISO 8583 version used.