# new FabricClientDispatch(client)
Listens for and processes events emitted by Fabric chaincode, dispatching them to registered observers
Event dispatcher for Hyperledger Fabric chaincode events
Parameters:
| Name | Type | Description |
|---|---|---|
client |
gRPC client for connecting to the Fabric network |
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
Methods
# async close() → {Promise.<void>}
Stops listening for chaincode events and releases resources
Closes the event listening connection
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
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
ctxArg |
FabricClientContext
|
<optional> |
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
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 |
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 |
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 |
A promise that resolves when all observers have been notified
Promise.<void>