hyperledger-fabrichyperledger-fabric-sdk-java

How to enable discover role when joining a channel from a peer


I am having following error when trying to execute a transaction using the Discovery service from Fabric Java SDK

org.hyperledger.fabric.sdk.exception.ServiceDiscoveryException: The channel is not configured with any peers with the 'discover' role

I joined the channel using peer shell command, not the Fabric Java SDK. How can I configure that discover role in the channel once it is already joined?

Thanks


Solution

  • I came up with the exact missing part of code. Hope it helps someone with a similar issue. It was just a matter of adding the required peerRoles as @david_k comments:

    I had:

    channel.addPeer(peer);
    

    and replacing it with this fixed the issue:

    channel.addPeer(peer, createPeerOptions().setPeerRoles(EnumSet.of(PeerRole.SERVICE_DISCOVERY, PeerRole.LEDGER_QUERY, PeerRole.EVENT_SOURCE, PeerRole.CHAINCODE_QUERY)));