-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: hmoazzem <moazzem@edgeflare.io>
- Loading branch information
Showing
10 changed files
with
183 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/edgeflare/pgo/pkg/pipeline" | ||
"github.com/edgeflare/pgo/pkg/x/logrepl" | ||
) | ||
|
||
func pipelinesDemo() error { | ||
// Check if PGO_POSTGRES_LOGREPL_CONN_STRING is set | ||
if os.Getenv("PGO_POSTGRES_LOGREPL_CONN_STRING") == "" { | ||
return fmt.Errorf("PGO_POSTGRES_LOGREPL_CONN_STRING environment variable is not set") | ||
} | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
// Set up signal handling for graceful shutdown | ||
sigChan := make(chan os.Signal, 1) | ||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
// Start consuming CDC events | ||
eventsChan, err := logrepl.Run(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Get the pipeline manager | ||
m := pipeline.Manager() | ||
// TODO: should also take config here | ||
m.AddPeer(pipeline.ConnectorMQTT, "mqtt-default") | ||
m.AddPeer(pipeline.ConnectorDebug, "debug") | ||
// TODO: add more peers | ||
|
||
// Initialize all peers | ||
for _, p := range m.Peers() { | ||
// use config it not nil. then check env var. finally fall back to defaults | ||
err := p.Connector().Init(nil) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize connector %s: %w", p.Name(), err) | ||
} | ||
} | ||
|
||
// Process events in a separate goroutine for each peer | ||
for _, p := range m.Peers() { | ||
go func(peer pipeline.Peer) { | ||
for event := range eventsChan { | ||
err := peer.Connector().Publish(event) | ||
if err != nil { | ||
log.Printf("Error publishing to %s: %v", peer.Name(), err) | ||
} | ||
} | ||
}(p) | ||
} | ||
|
||
log.Println("Logical replication started. Press Ctrl+C to exit.") | ||
|
||
// Wait for termination signal | ||
<-sigChan | ||
log.Println("Received termination signal, shutting down gracefully...") | ||
|
||
// Trigger cancellation of the context | ||
cancel() | ||
|
||
log.Println("Shutdown complete") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters