Class

FabricClientDispatch

FabricClientDispatch(client)

Constructor

# new FabricClientDispatch(client)

Listens for and processes events emitted by Fabric chaincode, dispatching them to registered observers

Event dispatcher for Hyperledger Fabric chaincode events

sequenceDiagram participant Client participant FabricDispatch participant Gateway participant Network participant Chaincode Client->>FabricDispatch: new FabricDispatch(client) Client->>FabricDispatch: configure(peerConfig) Client->>FabricDispatch: observe(table, event, callback) Client->>FabricDispatch: start() FabricDispatch->>FabricDispatch: initialize() FabricDispatch->>Gateway: getGateway(config, client) Gateway->>Network: getNetwork(channel) Network->>Network: getChaincodeEvents(chaincodeName) FabricDispatch->>FabricDispatch: handleEvents() loop For each event Chaincode-->>FabricDispatch: ChaincodeEvent FabricDispatch->>FabricDispatch: parseEventName(eventName) FabricDispatch->>FabricDispatch: parsePayload(payload) FabricDispatch->>FabricDispatch: updateObservers(table, event, id) FabricDispatch-->>Client: callback(id) end
Parameters:
Name Type Description
client

gRPC client for connecting to the Fabric network

View Source client/FabricClientDispatch.ts, line 7

Example
```typescript
// Create a new FabricDispatch instance
const client = await FabricAdapter.getClient(peerConfig);
const dispatch = new FabricDispatch(client);

// Configure the dispatch with peer configuration
dispatch.configure(peerConfig);

// Register an observer for a specific table and event
dispatch.observe('users', 'create', (id) => {
  console.log(`User created: ${id}`);
});

// Start listening for events
await dispatch.start();
```

Classes

FabricClientDispatch

Initializes a dispatcher for Fabric chaincode events

FabricClientDispatch

Initializes a dispatcher for Fabric chaincode events

Members

# decoder

Text decoder for converting event payloads from bytes to strings

.

Text decoder for converting event payloads from bytes to strings

View Source client/FabricClientDispatch.ts, line 64

# listeningStack

Event listening stack for chaincode events

.

Event listening stack for chaincode events

View Source client/FabricClientDispatch.ts, line 60

Methods

# async close() → {Promise.<void>}

Stops listening for chaincode events and releases resources

Closes the event listening connection

View Source client/FabricClientDispatch.ts, line 237

Promise that resolves when the connection is closed

Promise.<void>

# async protected handleEvents(ctxArgopt) → {Promise.<void>}

Listens for events from the chaincode and dispatches them to registered observers

Processes incoming chaincode events

sequenceDiagram participant FabricDispatch participant EventStack participant EventParser participant Observers FabricDispatch->>FabricDispatch: handleEvents() FabricDispatch->>EventStack: for await (const evt of listeningStack) EventStack-->>FabricDispatch: ChaincodeEvent FabricDispatch->>EventParser: parseEventName(evt.eventName) EventParser-->>FabricDispatch: { table, event, owner } FabricDispatch->>FabricDispatch: Check if event is for this MSP FabricDispatch->>FabricDispatch: parsePayload(evt.payload) FabricDispatch->>Observers: updateObservers(table, event, payload.id) Observers-->>FabricDispatch: Callbacks executed
Parameters:
Name Type Attributes Description
ctxArg FabricClientContext <optional>

View Source client/FabricClientDispatch.ts, line 291

Promise that resolves when event handling stops

Promise.<void>

# async protected initialize() → {Promise.<void>}

Sets up the connection to the Fabric network and starts listening for chaincode events

Initializes the event listener

View Source client/FabricClientDispatch.ts, line 300

Promise that resolves when initialization is complete

Promise.<void>

# observe(observer) → {void}

Connects this dispatch to an adapter to monitor its operations

Starts observing an adapter

Parameters:
Name Type Description
observer Adapter.<any, any, any, any>

The adapter to observe

View Source client/FabricClientDispatch.ts, line 254

void

# parsePayload(jsonBytes) → {Object}

Converts a Uint8Array containing JSON to an object with an id property

Parses event payload from binary format

Parameters:
Name Type Description
jsonBytes Uint8Array

The binary payload from the chaincode event

View Source client/FabricClientDispatch.ts, line 89

The parsed payload containing the record ID

Object

# async updateObservers(table, event, payload) → {Promise.<void>}

Notifies observers about a change in the database

Updates observers about a database event

Parameters:
Name Type Description
table string

The name of the table where the change occurred

event OperationKeys | BulkCrudOperationKeys | string

The type of operation that occurred

payload any

The event payload

View Source client/FabricClientDispatch.ts, line 265

A promise that resolves when all observers have been notified

Promise.<void>