Search code examples
javaswingapache-kafkadesktop

Updating desktop UI based on data in a Kafka topic


I'm making my first project with Kafka. I have a desktop client written in Java (Swing) that is used by managers of some marketplace and a web client for the customers. Customer fills a form for an order and data of this form is sent to Kafka topic. I need every manager to see every order immediately, so desktop client consumes data from the topic and shows it. Manager can perform some actions with the orders (lets say delete an order), and then i need every other client to update their UIs. So if ManagerOne deletes an order, ManagerTwo and ManagerThree will see this order deleted immediately. How can i achieve this? I'm thinking towards deleting a message from topic and then somehow alerting all clients to update, but that sounds like connecting clients and i do not think this is a good idea. Can i do this using Kafka features, or do i need to build some abstraction over it?


Solution

  • Kafka has no query functions other than scanning a topic. If you want to build tables and analytics around it, you'll need something extra.

    deleting a message from topic

    Data in Kafka is immutable, so that is not possible.

    and a web client for the customers

    Kafka has no direct interaction with web-pages. You'll need a different solution for this, such as Kafka Streams Interactive Queries with an RPC system (such as HTTP-based REST API).

    An example of this was put together by an old co-worker - https://github.com/ExpediaGroup/hello-streams

    Otherwise, you can build a traditional N-tier system where you use Kafka Connect to dump data to a database, then all clients connect to that database via some other API.