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

329 Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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)));
2
On

The concept of the discover role is a Fabric Java SDK concept. When you create your channel definition using the SDK and add a peer to it you would need to define that peer as having the discover role.

This is all handled for you if you use the fabric-gateway-java SDK package rather than the fabric-sdk-java package. The fabric-gateway-java package provides an easier entry into writing fabric client apps in java although not as powerful as using fabric-sdk-java.