Location>code7788 >text

XXL-TOOL v1.4.0 release | Java tool library

Popularity:718 ℃/2025-05-04 12:25:18

Release Notes

  • 1. [Newly added] JsonRpc module: a lightweight, cross-language remote procedure call implementation, based on json and http implementation (refined abstraction from the underlying communication components of XXL-JOB).
  • 2. [Newly added] Concurrent module: a series of concurrent programming tools, with good thread safety, high concurrency and high performance advantages, including CyclicThread (cyclic thread), MessageQueue (high-performance memory queue, 30W+ TPS), etc.
  • 3. [New] Auth module: a series of permission authentication-related tools, including JwtTool, etc.
  • 4. [Strength] The existing tools have been improved, including CollectionTool, MapTool, HttpTool, etc.;
  • 5. [Upgrade] Upgrade dependent versions, including slf4j, poi, spring, gson, junit, etc.

Introduction

XXL-TOOL is a Java tool library that is committed to making Java development more efficient. It contains dozens of modules such as "collection, string, cache, concurrency, Excel, Emoji, Response, Pipeline...".

Document address

  • Chinese Documentation:/xxl-tool/
  • Github:/xuxueli/xxl-tool

Component list

Module illustrate
Core module Includes basic component tools such as collections, caches, dates, etc.
IO module A series of tools for handling IO (input/output) operations.
Concurrent module A series of concurrent programming tools have good thread safety, high concurrency and high performance advantages, including MessageQueue (high-performance memory queue, 30W+ TPS), CyclicThread (backend loop thread), TimeWheel (time wheel component), etc.
Http module A series of related tools for handling Http communication, IP, cookies and other related tools.
Gson module json serialization and deserialization tool encapsulation, based on Gson.
Excel module A flexible tool for converting Java objects and Excel documents to each other. A line of code completes the conversion between Java objects and Excel.
Emoji module A flexible and extensible Emoji emoticon codec library can quickly implement Emoji emoticon codec.
JsonRpc module A lightweight, cross-language remote procedure call implementation, based on json and http implementation (compared with the traditional RPC framework:XXL-RPC)。
Response module Unified response data structures, standardize data structures, status codes, etc., and reduce collaboration costs.
Pipeline module Highly scalable process orchestration engine.
Exception module Exception handling related tools.
Freemarker module The template engine tool supports dynamic text generation, static file generation, etc. based on template files, and supports mail sending and static web page scenarios.
Encrypt module A series of tools for coding, encoding, encryption and decryption, including Md5Tool, HexTool, Base64Tool... etc.
Auth module A series of permission authentication-related tools, including JwtTool... etc.
... ...

Code example: JsonRpc usage

A lightweight, cross-language remote procedure call implementation, based on json and http.

first step: RPC business service development

public interface UserService {
    public ResultDTO createUser(UserDTO userDTO);
    public UserDTO loadUser(String name);
    ... ...
}

Step 2: JsonRpc server configuration

// a. JsonRpcServer initialization
 JsonRpcServer jsonRpcServer = new JsonRpcServer();

 // b. Business service registration (supports multiple service registration)
 ("userService", new UserServiceImpl());

 // c. Web framework integration, this entry is an RPC unified traffic entrance (springmvc integration; theoretically supports any web framework integration, and other framework reference integration)
 @RequestMapping("/openapi")
 @ResponseBody
 public String api(@RequestBody(required = false) String requestBody){
	 // Core code: The RequestBody requested by Http is used as the entry parameter; the service response is used as the output;
     return (requestBody);
 }

Step 3: JsonRpc client configuration

// Method 1: Use the proxy method (build a proxy for the interface and realize remote calls through the proxy object;)
 UserService userService = new JsonRpcClient("http://localhost:8080/jsonrpc", 3000).proxy("userService", );

 // Initiate an RPC request;
 UserDTO result = ("zhangsan");

Code example: MessageQueue (High-performance memory queue)

High-performance memory queue, stand-alone support 30W+ TPS, has good performance and high concurrency advantages, and supports production and consumption models.

// a. Define queue: specify the number of consumers, batch consumption quantity, consumer logic, etc.
 MessageQueue<String> messageQueue = new MessageQueue<>(
	 "demoQueue",
	 messages -> {
		 // Consumption logic
		 ("Consume: " + messages);
	 },
	 10, // Custom consumer thread
	 20 // Customize the quantity of batch consumption
 );

 // b. Production news
 ("test-" + i);

Code example: TimeWheel (Time Wheel)

The implementation of time round algorithm has the advantages of high precision, multi-tasking, and thread safety.

// a. Time round definition, custom time round scale, interval, etc.
 TimeWheel timeWheel = new TimeWheel(60, 1000);

 // b. Submit time round tasks (timed tasks)
 (() + 3000, () -> {
     ("Task delay " + waitTime + "ms executed at: " );
 });

Code example: Jwt permission authentication

JWT tool, providing JWT generation and parsing capabilities

// a. JwtTool initialization, custom Signer and Verifier
 JwtTool jwtTool = new JwtTool(SECRET); // MACSigner/MACVerifier is used by default, supporting custom implementations of multiple construction methods;

 // b. Create a token
 String token = (
                 {user ID},
                 {custom declaration data, map form},
                 {custom expiration time}
         );
        
 // c. Verify token
 boolean isValid = (token);
 // d. Get claim
 Object userId = (token, {custom declaration data key});
 // e. Obtain the expiration time
 Date expirationTime = (token);