Skip to content

josemasuarez/thrift-demo-multiplier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thrift Demo Project

This Java project is a simple Thrift demo that aims to demonstrate how Thrift works. In this guide, we'll walk you through the process of generating the required Java code using Thrift and executing the project.

Prerequisites

Before getting started, make sure you have the following prerequisites installed:

  • Thrift compiler
  • Maven

Generating Java Code with Thrift

  1. Open your terminal and navigate to the root folder of the project.

  2. Run the following command to generate Java code from the Thrift definition file (multi.thrift):

thrift -r --gen java multi.thrift

This command will create the Java code in the gen-java folder.

  1. After generating the code, you need to move it to the src/org/example directory. You can do this manually or by using the following command:
mv gen-java/* src/org/example/

Building and Running the Project

Now that you have generated the required Java code, you can build and run the Thrift demo project.

  1. Execute the following command to clean the project:
mvn clean
  1. Next, build and package the project into a JAR file:
mvn install jar
  1. The project consists of two main classes:
  • MultiplicationServer: This class has a main method that triggers a thread to start the Thrift server.

  • MultiplicationClient: This class has a main method that connects to the server started in the previous step.

You can run these classes as follows:

  • To start the server, run the MultiplicationServer class:
java -cp target/<your-jar-filename>.jar org.example.MultiplicationServer
  • To run the client, execute the MultiplicationClient class:
java -cp target/<your-jar-filename>.jar org.example.MultiplicationClient

Replace <your-jar-filename> with the actual JAR file name generated by Maven.

Conclusion

You have successfully generated the Thrift Java code, built the project, and executed the Thrift demo. This project showcases how to create a Thrift-based server and client in Java, demonstrating the fundamentals of Thrift RPC communication. Feel free to explore and modify the project as needed for your own use case.

Happy coding!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published