+40
README.md
+40
README.md
···
31
31
* [Filtering Events](#filtering-events)
32
32
* [Queue Integration](#queue-integration)
33
33
* [Configuration](#configuration-1)
34
+
* [Programmatic Usage](#programmatic-usage)
34
35
* [Available Commands](#available-commands)
35
36
* [Testing](#testing)
36
37
* [External Resources](#external-resources)
···
601
602
\App\Signals\NewPostSignal::class,
602
603
\App\Signals\NewFollowSignal::class,
603
604
],
605
+
```
606
+
607
+
---
608
+
609
+
## Programmatic Usage
610
+
611
+
You can start and stop the consumer programmatically using the `Signal` facade:
612
+
613
+
```php
614
+
use SocialDept\Signal\Facades\Signal;
615
+
616
+
// Start consuming events (uses mode from config)
617
+
Signal::start();
618
+
619
+
// Start from a specific cursor
620
+
Signal::start(cursor: 123456789);
621
+
622
+
// Check which mode is active
623
+
$mode = Signal::getMode(); // Returns 'jetstream' or 'firehose'
624
+
625
+
// Stop consuming events
626
+
Signal::stop();
627
+
```
628
+
629
+
The facade automatically resolves the correct consumer (Jetstream or Firehose) based on your `config('signal.mode')` setting. This allows you to:
630
+
631
+
- Switch between modes by changing configuration
632
+
- Start consumers from application code (e.g., in a custom command)
633
+
- Integrate Signal into existing application workflows
634
+
635
+
```php
636
+
// Example: Start consumer based on environment
637
+
if (app()->environment('production')) {
638
+
config(['signal.mode' => 'jetstream']); // Use efficient Jetstream
639
+
} else {
640
+
config(['signal.mode' => 'firehose']); // Use comprehensive Firehose for testing
641
+
}
642
+
643
+
Signal::start();
604
644
```
605
645
606
646
---