-
Notifications
You must be signed in to change notification settings - Fork 61
config
Java sdk主要包括五个配置选项,分别是证
-
证书配置 (必须)
-
网络连接配置 (必须)
-
AMOP配置(可选)
-
账户配置(可选)
-
线程池配置。(可选)
基于安全考虑,java sdk与节点间采用SSL加密通信,目前同时支持非国密SSL连接以及国密SSL连接,[cryptoMaterial]配置SSL连接的证书信息,具体包括如下配置项:
-
certPath: 证书存放路径,默认是conf目录; -
caCert: CA证书路径,默认注释该配置项,该配置项注释时,当SDK与节点间采用非国密SSL连接时,默认的CA证书路径为${certPath}/ca.crt,当SDK与节点采用国密SSL连接时,默认的CA证书路径为${certPath}/gm/gmca.crt;开启该配置项时,从配置指定的路径加载CA证书; -
sslCert: SDK证书路径,默认注释该配置项,该配置项注释时,当SDK与节点间采用非国密SSL连接时,从${certPath}/sdk.crt加载SDK证书,当SDK与节点间采用国密SSL连接时,从${certPath}/gm/gmsdk.crt加载SDK证书;开启该配置选项时,从配置指定的路径加载SDK证书; -
sslKey: SDK私钥路径,默认注释该配置项,当该配置项注释时,当SDK与节点间采用非国密SSL连接时,从${certPath}/sdk.key加载SDK私钥,SDK与节点采用国密SSL连接时,从${certPaht}/gm/gmsdk.key加载SDK私钥;开启该配置项时,直接从配置项指定的路径加载SDK私钥; -
enSslCert: 国密SSL加密证书路径,仅当SDK与节点间采用国密SSL连接时,需要配置该配置项,默认从${certPath}/gm/gmensdk.crt加载国密SSL加密证书;当开启该配置项时,从配置项指定的路径加载国密SSL加密证书; -
enSslKey: 国密SSL加密私钥路径,仅当SDK与节点间采用国密SSL连接时,需配置该配置项,默认从${certPath}/gm/gmensdk.key加载国密SSL加密私钥;当卡其该配置项时,从配置项指定的路径加载国密SSL加密私钥。
SDK证书配置示例如下:
[cryptoMaterial]
certPath = "conf" # The certification path
# The following configurations take the certPath by default:
# caCert = "conf/ca.crt" # CA cert file path
# sslCert = "conf/sdk.crt" # SSL cert file path
# sslKey = "conf/sdk.key" # SSL key file path
# enSslCert = "conf/gm/gmensdk.crt" # GM encryption cert file path
# enSslKey = "conf/gm/gmensdk.key" # GM ssl cert file pathSDK与FISCO BCOS节点通信,必须配置SDK连接的节点的IP和Port,[network]配置了java sdk连接的节点信息,具体包括如下配置项:
- peers:SDK连接的节点的
IP:Port信息,可配置多个连接。
.. note::
节点与网络之间的连接信息
SDK与节点间通过 `ChannelServer` 进行通信,SDK需要连接 `ChannelServer` 的监听端口,该端口可通过节点 `config.ini` 的 `rpc.channel_listen_port` 获取,具体请参考 `这里 <../../manual/configuration.html#rpc>`_
SDK与节点间的网络配置示例如下:
[network]
peers=["127.0.0.1:20200", "127.0.0.1:20201"] # The peer list to connectAMOP支持私有话题的功能,配置文件中提供了AMOP相关配置项于 [[amop]]中。
AMOP私有话题订阅者需要配置私钥用于进行私有话题认证,具体配置项包括:
-
topicName: 私有话题名称; -
privateKey: 私有话题订阅者的私钥路径,用于证明订阅房身份信息; -
password: 访问私钥文件的口令。
AMOP订阅私有话题的配置项示例如下:
# Configure a private topic as a topic subscriber.
# [[amop]]
# topicName = "PrivateTopic2"
# privateKey = "conf/amop/consumer_private_key.p12" # Your private key that used to subscriber verification.
# password = "123456"AMOP私有话题认证成功后,消息发布方可向订阅方发送私有话题消息,发布私有话题消息的配置包括:
-
topicName: 私有话题名称; -
publicKeys: 消息订阅方的公钥列表。
AMOP发布私有话题消息的配置示例如下:
# Configure a private topic as a topic message sender.
# [[amop]]
# topicName = "PrivateTopic1"
# publicKeys = [ "conf/amop/consumer_public_key_1.pem" ] # Public keys of the nodes that you want to send AMOP message of this topic to.账户配置主要用于设置SDK向节点发交易的账户信息,SDK初始化client时,默认读取[account]配置项加载账户信息,具体如下:
-
keyStoreDir: 加载/保存账户文件的路径,默认为account; -
accountFileFormat: 账户文件格式,默认为pem,目前仅支持pem和p12,pem格式的账户文件不需要口令加载,加载p12格式的账户文件时需要口令; -
accountAddress: 加载的账户地址,默认为空 -
accountFilePath: 加载的账户文件路径,默认注释该配置项,注释该配置项时,当SDK连接非国密区块链时,默认从${keyStoreDir}/ecdsa/${accountAddress}.${accountFileFormat}路径加载账户文件,当SDK连接国密区块链时,默认从${keyStoreDir}/gm/${accountAddress}.${accountFileFormat}路径加载账户;当开启该配置项时,从该配置项指定的目录加载账户; -
password: 加载p12类型账户文件的口令。
.. note::
当没有配置 `accountAddress` 和 `accountFilePath` 时,SDK会生成随机的账户向节点交易,生成的账户信息均保存在 `keyStoreDir` 配置项指定的目录下:当SDK连接节点是非国密节点时,生成的临时账户以 `pem` 的格式保存在 `${keyStoreDir}/ecdsa/` 目录下;当SDK连接的节点时国密节点时,生成的临时账户以 `p12` 的格式保存在 `${keyStoreDir}/gm` 目录下
账户配置文件示例如下:
[account]
keyStoreDir = "account" # The directory to load/store the account file, default is "account"
# accountFilePath = "" # The account file path (default load from the path specified by the keyStoreDir)
accountFileFormat = "pem" # The storage format of account file (Default is "pem", "p12" as an option)
# accountAddress = "" # The transactions sending account address
# Default is a randomly generated account
# The randomly generated account is stored in the path specified by the keyStoreDir
# password = "" # The password used to load the account file为了方便业务根据机器实际负载调整SDK的处理线程,java sdk将其线程配置项暴露在配置中,[threadPool]是线程池相关配置,具体包括:
-
channelProcessorThreadSize: 处理网络回调的线程数目,默认注释该配置项,注释该配置项时,其默认值为机器的CPU数目;开启该配置项时,根据配置的值创建处理网络回调的线程数目; -
receiptProcessorThreadSize: 接收交易的线程数目,默认注释该配置项,注释该配置项时,默认值为机器的CPU数目;开启该配置项时,根据配置的值创建接收交易的线程数目; -
maxBlockingQueueSize: 线程池队列等待被处理的最大任务数目,默认为102400。
.. note::
大多数场景下,不需要手工配置线程池配置;压测场景下,可将 `maxBlockingQueueSize` 配置大一些。
线程池配置示例如下:
[threadPool]
# channelProcessorThreadSize = "16" # The size of the thread pool to process channel callback
# Default is the number of cpu cores
# receiptProcessorThreadSize = "16" # The size of the thread pool to process transaction receipt notification
# Default is the number of cpu cores
maxBlockingQueueSize = "102400" # The max blocking queue size of the thread pool