All Products
Search
Document Center

The API client of attestation service

Last Updated: Jan 17, 2019

The API client of attestation service is connected to the blockchain node using a custom RPC protocol. This document introduces the principle and configuration of the API client implemented by the Java SDK.

Client

The client class is the implementation of the API communication protocol antblockchain-gl and it is thread-safe. Multithreading can significantly improve the performance of the SDK, but more is not always better. Users need to test and determine the most reasonable number of threads based on the actual requirements.

The client uses a delayed connection. It does not connect to the server immediately after being created, and attempts to connect to the server only when an interface call occurs. The default number of attempts is 3. Each time, the client attempts to connect to the primary node before attempting to connect to all backup nodes. Once the primary node fails to connect, the primary node connection attempt will be made at regular intervals (the default is 10 seconds). And if it is already connected to a backup node at the time, the connection with the backup node will be disconnected and the primary node connection will be reselected. In conclusion, the consortium blockchain network is typically inter-organizational, and only the nodes of the organization itself (the primary node) have the best network environment. The network delay for other backup nodes (typically the nodes of other organizations) can be high, therefore the client chooses to connect to the primary node whenever possible.

The client does not have a retransmission mechanism for failed requests. For example, if the connection is disconnected during the request transmission and the request transmission fails, the reponse returned by the interface contains errorMsg, and it is up to the caller to decide whether to resend the request.

The netty in the client has only one IO thread, and only one channel to connect to the server. The IO thread only handles read and write operations, and all business logic is processed in the business thread pool. The SSL provider used by the client is netty-tcnative-boringssl-static, which has higher performance than the provider provided by Java.

Config

ClientConfig is required to create a client. ClientConfig is an interface and the SDK provides the default implementation of ClientPropertyConfig. ClientPropertyConfig obtains the configuration by reading the properties file.

ClientPropertyConfig Description Required Value
biz.sdk.primary The API address of the primary node. One and only one primary node can be configured Yes 127.0.0.0:8080
biz.sdk.backups The API address of the backup node. 0 or more backup nodes can be configured No 127.0.0.0:8080;127.0.0.0:8081
biz.sdk.primary_auto_reconnect_interval The interval (in seconds) between automatic attempts to reconnect after the failure of the primary node No The default is 10 seconds
biz.sdk.ssl_key The absolute path of the SSL private key files in pkcs8 format No The default is empty
biz.sdk.ssl_cert The absolute path of the SSL certificate files in x509 format No The default is empty
biz.sdk.ssl_key_password The password for the SSL private key No The default is empty
biz.sdk.trust_store The absolute path of the trust store files No The default is empty
biz.sdk.trust_store_password The password of the trust store No The default is empty
biz.sdk.protocol The name of the communication protocol. If it is null, the default protocol name is used No The default is 1.0
biz.sdk.biz_thread_pool_size The size of the service thread pool. If it is not a positive number, the default size of the service thread pool is used No The default is the number of CPU cores × 2
biz.sdk.read_idle_time Read idle time (in seconds), after which the SDK will send a ping message to the server No The default is 60 seconds
biz.sdk.send_one_way_message_timeout One-way transmission timeout (in milliseconds), after which the transmission is considered to have failed No The default is 15,000
biz.sdk.wait_response_timeout Two-way response timeout (in milliseconds), after which the response is considered to have failed No The default is 30,000
biz.sdk.socket_send_buffer_size The size of the socket send buffer. If it is not a positive number, the Java default buffer size is used No The default is 0
biz.sdk.socket_recv_buffer_size The size of the socket receive buffer. If it is not a positive number, the Java default buffer size is used No The default is 0
biz.sdk.tcp_no_delay Whether to enable the Nagle algorithm No The default is false
biz.sdk.explicit_flush_after_flushes The flush merging policy threshold of netty. If it is a positive number, flush merging is enabled No The default is 0

All API addresses can be written in one of two ways: 127.0.0.1:8080 or 127.0.0.1 8080

The server does not have SSL enabled in the current test network, so the client does not need to configure the SSL parameters. If the request sent is relatively large, the send buffer of the socket can be appropriately set to a larger size. Set tcp_no_delay carefully. If a single thread uses the client and the packet sent is small, it is easy to encounter a 40 ms delay. If the package sent is small and the frequency is high, you can try to enable flush merging, which can help improve performance.