org.hyperledger.fabric.gateway

## 接口 Gateway

- 所有超级接口:
    AutoCloseable

      public interface Gateway
      extends AutoCloseable

  The Gateway provides the connection point for an application to access the Fabric network as a specific user. It is instantiated from a Builder instance that is created using `createBuilder()` and configured using a common connection profile and a `Wallet` identity. It can then be connected to a fabric network using the `Gateway.Builder.connect()` method. Once connected, it can then access individual `Network` instances (channels) using the `getNetwork` method which in turn can access the `Contract` installed on a network and `submit transactions` to the ledger.

  Gateway instances should be reused for multiple transaction invocations and only closed once connection to the Fabric network is no longer required.

           Gateway.Builder builder = Gateway.createBuilder()
                   .identity(wallet, "user1")
                   .networkConfig(networkConfigFile);

           try (Gateway gateway = builder.connect()) {
               Network network = gateway.getNetwork("mychannel");
               // Interactions with the network
           }

  ## Service discovery

  Service discovery allows the client to dynamically discover nodes (peers and orderers) within a network that are not defined in the connection profile, and is enabled using `Gateway.Builder.discovery(boolean)`. With service discovery enabled, the client will receive the public network address of each node. If these network addresses can be reached directly by the client, no additional configuration is required.

  In some cases nodes cannot be accessed directly by the client on their public network address. For example, when nodes are hosted in Docker containers, and the client is running on the local machine outside of the Docker network. In this case service discovery will report the network address of nodes within the Docker network but the client will need to access nodes using the localhost address. Setting the following environment variable will force service discovery to report the localhost address for all nodes.

      org.hyperledger.fabric.sdk.service_discovery.as_localhost=true

  An alternative approach is to modify the local hosts file for the client machine to resolve the network address of nodes running in a Docker network to the localhost address.

  Note that the port numbers of nodes obtained through service discovery remain unchanged so ports forwarded from the local machine's network must match the port numbers of nodes within the Docker network.

  另请参阅:
    Developing Fabric Applications - Gateway

- - ### 嵌套类概要

    嵌套类
    限定符和类型 | 接口和说明
    --- | ---
    `static interface` | `Gateway.Builder` The Gateway Builder interface defines the options that can be configured prior to connection.

  - ### 方法概要

    所有方法 静态方法 实例方法 抽象方法 默认方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `close()` Close the gateway connection and all associated resources, including removing listeners attached to networks and contracts created by the gateway.
    `static Gateway.Builder` | `createBuilder()` Creates a gateway builder which is used to configure the gateway options prior to connecting to the Fabric network.
    `Identity` | `getIdentity()` Get the identity associated with the gateway connection.
    `Network` | `getNetwork(String networkName)` Returns an object representing a network.

- - ### 方法详细资料

    - #### getNetwork

          Network getNetwork(String networkName)

      Returns an object representing a network.
      参数:
        `networkName` - The name of the network (channel name)
      返回:
        `Network`
      抛出:
        `GatewayRuntimeException` - if a configuration or infrastructure error causes a failure.

    - #### getIdentity

          Identity getIdentity()

      Get the identity associated with the gateway connection.
      返回:
        The identity used by this Gateway.

    - #### createBuilder

          static Gateway.Builder createBuilder()

      Creates a gateway builder which is used to configure the gateway options prior to connecting to the Fabric network.
      返回:
        A gateway connection.

    - #### close

          void close()

      Close the gateway connection and all associated resources, including removing listeners attached to networks and contracts created by the gateway.
      指定者:
        `close` 在接口中 `AutoCloseable`

Copyright © 2023. All rights reserved.