How to publish messages directly from existing Mainframe application to Kafka topics?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Integrating mainframe applications with modern event streaming platforms like Apache Kafka is essential for businesses that need real-time data processing and analytics. In this article, we will explore how you can publish messages directly from existing mainframe applications to Kafka topics.
Understanding the Environment
Mainframes are powerful servers traditionally used for applications that require high volumes of data processing and transaction handling, like financial transactions. Apache Kafka is a distributed streaming platform capable of handling trillions of events a day. Thus, integrating both can leverage the robustness of mainframes with Kafka's real-time processing capabilities.
Methods of Integration
There are principally two methods to achieve the integration of mainframe data to Kafka:
- Direct Integration: Writing a custom program on the mainframe that produces messages directly to Kafka topics.
- Indirect Integration: Using middleware or off-the-shelf solutions that act as a bridge between the mainframe and Kafka.
Direct Integration with Kafka
Direct integration is achievable through applications written on the mainframe. These programs can be in COBOL, PL/I, or any language that supports accessing Kafka's API. The main challenge here is that Kafka is primarily supported on Linux, UNIX, and Windows platforms, and most mainframes run on z/OS. However, Kafka clients are available that can run under z/OS UNIX System Services (USS).
Step-by-Step Guide
- Install Kafka Client: Install a Kafka client that is compatible with z/OS. This client will be able to communicate with Kafka brokers.
- Configure Kafka Producer: Set up the Kafka producer configurations necessary to connect to the Kafka cluster. This includes the broker's address, port, and any security protocols in place.
- Writing the Producer Application: Write a mainframe application that uses the Kafka client library to create messages and send them to Kafka. This application can be written in languages like Java running on the z/OS platform.
- Error Handling and Logging: Implement robust error handling and logging within the application to handle any connection failures, message delivery confirmations, and other runtime exceptions.
- Testing and Validation: Perform thorough testing to ensure that messages are correctly formatted, successfully sent to the appropriate Kafka topic, and that Kafka consumers can read these messages.
Example Code in Java
Here is a simple example of a Java program running on z/OS that sends a message to a Kafka topic:
Summary Table
| Integration Type | Technologies Used | Pros | Cons |
| Direct | Java, Kafka Client for z/OS | Higher control and customization | More developer effort required |
| Indirect | Middleware Solutions | Easier to set up and maintain | Might require purchasing additional software |
Additional Considerations
- Security: Ensure that sensitive data is encrypted and that proper security protocols are adhered to during data transmission.
- Scalability: The solution must handle the volume of transactions typical for a mainframe.
- Maintenance: Regular updates and checks should be scheduled for both the Kafka system and any integration software.
In summary, pulling data from a mainframe to Kafka directly involves understanding both systems' capabilities and limitations. This requires careful planning and technical expertise but results in a powerful tool for real-time data streaming and processing.
Related reading
- How to push messages from unacked to ready, rabbitmq
- How to put data from MySQL to Kafka producer?
- How to quickly stop seda in camel
- how to re-register zookeeper watches
- How to read all the records in a Kafka topic
- How to read data using key in Kafka Consumer API?
- How to read json data using scala from kafka topic in apache spark
- How to read messages from kafka consumer group without consuming?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.