Consumers
Consumers are a vital component of the Blueprint Runner architecture that handle the results of processed jobs. This document explains how consumers work, how to configure them, and best practices for implementation.
What are Consumers?
In a Blueprint Runner, consumers are responsible for handling the results of job execution. They:
- Receive results from jobs via the router
- Process and transform these results as needed
- Perform actions based on the results, such as:
- Sending transactions to the blockchain
- Updating local state
- Triggering other processes
- Storing data for later use
- Emitting events or notifications
Consumers act as the output handlers of your Blueprint Runner, ensuring that job results lead to appropriate actions.
Consumer Configuration
Consumers are typically configured in the main.rs
file of your Blueprint binary, when defining the Blueprint Runner. The configuration involves:
- Creating a consumer
- Defining how it processes job results
- Connecting it to jobs via the router
Basic Consumer Setup
First, you define the consumer you want to use. For example, a TangleConsumer
that listens for finalized blocks on Tangle. After which, you pass the consumer to the Blueprint Runner’s builder.
let env = BlueprintEnvironment::load()?;
let sr25519_signer = env.keystore().first_local::<SpSr25519>()?;
let sr25519_pair = env.keystore().get_secret::<SpSr25519>(&sr25519_signer)?;
let sr25519_signer = TanglePairSigner::new(sr25519_pair.0);
let tangle_client = env.tangle_client().await?;
let tangle_producer = TangleProducer::finalized_blocks(tangle_client.rpc_client.clone()).await?;
let tangle_consumer = TangleConsumer::new(tangle_client.rpc_client.clone(), sr25519_signer);
BlueprintRunner::builder(tangle_config, env)
.router(router) // Assuming your router is already defined
.producer(tangle_producer)
.consumer(tangle_consumer)
.run()
.await?;
Types of Consumers
Blueprint Runners can utilize various types of consumers depending on the requirements:
Tangle Consumer
A Tangle Consumer is a consumer that handles transactions on the Tangle, submitting job results for a Blueprint.
EVM Consumer
An EVM Consumer is a consumer that handles transactions on the EVM, submitting job results for a Blueprint.
Integration with Other Components
Consumers work closely with other Blueprint Runner components:
- Routers: Routers pass job results to consumers for handling
- Producers: Results handled by consumers may generate new events for producers to process
Next Steps
Now that you understand consumers, learn about:
- Routers - How to direct job calls to appropriate handlers
- Producers - How to capture and process events
- Building a Blueprint Runner - Step-by-step guide to building your own Blueprint Runner
Conclusion
Consumers are essential components that translate job results into meaningful actions in your Blueprint Runner. By implementing robust and efficient consumers, you can ensure that your Blueprint operates reliably and effectively.