Skip to content

Commit 6d04128

Browse files
committed
[FAB-4472] Improve documentation for block listener
This CR improves the documentation for the block listener example, which lacks clarity and is hard to follow. It also cleans up a few of the printed messages in the code. Change-Id: I65b612520f526cb5f3f0616868bac762f8719548 Signed-off-by: Will Lahti <[email protected]>
1 parent 85ef083 commit 6d04128

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

examples/events/block-listener/README.md

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
# What is block-listener
2-
block-listener.go will connect to a peer and receive block and chaincode events (if there are chaincode events being set).
3-
Currently, this example only runs with TLS disabled.
2+
block-listener.go connects to a peer in order to receive block and chaincode
3+
events (if there are chaincode events being sent). Currently, this example only
4+
works with TLS disabled in the environment.
45

56
# To Run
67
```sh
78
1. go build
89

9-
2. ./block-listener -events-address=< event address > -events-from-chaincode=< chaincode ID > -events-mspdir=< msp directory > -events-mspid=< msp id >
10+
2. ./block-listener -events-address=<peer-address> -events-from-chaincode=<chaincode-id> -events-mspdir=<msp-directory> -events-mspid=<msp-id>
1011
```
11-
Please be noted that if no msp info provided, it uses default MSP under fabric/sampleconfig.
12-
# Example with e2e
13-
Please make sure you have finished running the [e2e_cli example](https://github.com/hyperledger/fabric/tree/master/examples/e2e_cli). Before doing that, don't forget to make sure that TLS has been disabled by setting the CORE_PEER_TLS_ENABLED=***false*** in ``docker-compose-cli.yaml``, ``base/docker-compose-base.yaml`` and ``base/peer-base.yaml``.
12+
Please note that the default MSP under fabric/sampleconfig will be used if no
13+
MSP parameters are provided.
1414

15-
Suppose you just finished the All-in-one:
15+
# Example with the e2e_cli example
16+
In order to use the block listener with the e2e_cli example, make sure that TLS
17+
has been disabled by setting CORE_PEER_TLS_ENABLED=***false*** in
18+
``docker-compose-cli.yaml``, ``base/docker-compose-base.yaml`` and
19+
``base/peer-base.yaml``.
20+
21+
Next, run the [e2e_cli example](https://github.com/hyperledger/fabric/tree/master/examples/e2e_cli).
22+
23+
Once the "All in one" command:
1624
```sh
1725
./network_setup.sh up
1826
```
19-
Attach event client to peer peer0.org1.example.com (suppose you are running block-listener in the host environment):
27+
has completed, attach the event client to peer peer0.org1.example.com by doing
28+
the following (assuming you are running block-listener in the host environment):
2029
```sh
21-
./block-listener -events-address=127.0.0.1:7053 -events-mspdir=<peer0.org1.example.com's msp directory > -events-mspid=Org1MSP
30+
./block-listener -events-address=127.0.0.1:7053 -events-mspdir=$GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp -events-mspid=Org1MSP
2231
```
2332

24-
Event client should output "Event Address: 127.0.0.1:7053" and wait for events.
33+
The event client should output "Event Address: 127.0.0.1:7053" and wait for
34+
events.
2535

2636
Exec into the cli container:
2737

@@ -30,7 +40,7 @@ docker exec -it cli bash
3040
```
3141
Setup the environment variables for peer0.org1.example.com
3242
```sh
33-
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
43+
CORE_PEER_MSPCONFIGPATH=$GOPATH/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
3444
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
3545
CORE_PEER_LOCALMSPID="Org1MSP"
3646
```
@@ -40,8 +50,8 @@ Create an invoke transaction:
4050
```sh
4151
peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'
4252
```
43-
Now you should see the block content received in events client.
53+
Now you should see the block content displayed in the terminal running the block
54+
listener.
4455

4556

4657
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
47-
s

examples/events/block-listener/block-listener.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func createEventClient(eventAddress string, _ string) *adapter {
6262
adapter := &adapter{notfy: done}
6363
obcEHClient, _ = consumer.NewEventsClient(eventAddress, 5, adapter)
6464
if err := obcEHClient.Start(); err != nil {
65-
fmt.Printf("could not start chat %s\n", err)
65+
fmt.Printf("could not start chat. err: %s\n", err)
6666
obcEHClient.Stop()
6767
return nil
6868
}
@@ -149,14 +149,14 @@ func main() {
149149
if mspDir == "" {
150150
err := msptesttools.LoadMSPSetupForTesting()
151151
if err != nil {
152-
fmt.Printf("Could not initialize msp, err %s", err)
152+
fmt.Printf("Could not initialize msp, err: %s\n", err)
153153
os.Exit(-1)
154154
}
155155
} else {
156156
//load msp info
157157
err := mgmt.LoadLocalMsp(mspDir, nil, mspId)
158158
if err != nil {
159-
fmt.Printf("Could not initialize msp, err %s", err)
159+
fmt.Printf("Could not initialize msp, err: %s\n", err)
160160
os.Exit(-1)
161161
}
162162
}
@@ -188,16 +188,16 @@ func main() {
188188
if txsFltr.IsInvalid(i) {
189189
fmt.Println("")
190190
fmt.Println("")
191-
fmt.Printf("Received invalid transaction from channel %s\n", chdr.ChannelId)
191+
fmt.Printf("Received invalid transaction from channel '%s'\n", chdr.ChannelId)
192192
fmt.Println("--------------")
193193
fmt.Printf("Transaction invalid: TxID: %s\n", chdr.TxId)
194194
} else {
195-
fmt.Printf("Received transaction from channel %s: \n\t[%v]\n", chdr.ChannelId, tx)
195+
fmt.Printf("Received transaction from channel '%s': \n\t[%v]\n", chdr.ChannelId, tx)
196196
if event, err := getChainCodeEvents(r); err == nil {
197197
if len(chaincodeID) != 0 && event.ChaincodeId == chaincodeID {
198198
fmt.Println("")
199199
fmt.Println("")
200-
fmt.Printf("Received chaincode event from channel %s\n", chdr.ChannelId)
200+
fmt.Printf("Received chaincode event from channel '%s'\n", chdr.ChannelId)
201201
fmt.Println("------------------------")
202202
fmt.Printf("Chaincode Event:%+v\n", event)
203203
}

0 commit comments

Comments
 (0)