2024-12-16 15:34:44 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
2024-12-24 12:17:21 -06:00
|
|
|
"os/signal"
|
|
|
|
|
"syscall"
|
|
|
|
|
|
2026-02-22 14:24:12 -08:00
|
|
|
log "github.com/hanzoai/stream/logging"
|
|
|
|
|
"github.com/hanzoai/stream/protocol"
|
|
|
|
|
"github.com/hanzoai/stream/types"
|
2025-02-22 17:25:00 -06:00
|
|
|
"github.com/spf13/cobra"
|
2024-12-16 15:34:44 -06:00
|
|
|
)
|
|
|
|
|
|
2025-01-02 21:52:26 -06:00
|
|
|
var config = types.Configuration{
|
2026-02-22 13:38:22 -08:00
|
|
|
PubSubUrl: "nats://localhost:4222",
|
|
|
|
|
BrokerHost: "localhost",
|
|
|
|
|
BrokerPort: 9092,
|
2026-02-23 16:23:28 -08:00
|
|
|
AdminPort: 9093,
|
2026-02-22 13:38:22 -08:00
|
|
|
NodeID: 1,
|
|
|
|
|
StreamReplicas: 1,
|
|
|
|
|
StorageType: "file",
|
2024-12-16 15:34:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
2025-02-22 17:25:00 -06:00
|
|
|
var rootCmd = &cobra.Command{
|
2026-02-22 14:24:12 -08:00
|
|
|
Use: "hanzo-stream",
|
|
|
|
|
Short: "Hanzo Stream — Kafka wire protocol gateway for Hanzo PubSub",
|
2025-02-22 17:25:00 -06:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
broker := protocol.NewBroker(&config)
|
2026-02-23 16:23:28 -08:00
|
|
|
log.SetLogLevel(log.INFO)
|
2024-12-24 12:17:21 -06:00
|
|
|
|
2025-02-22 17:25:00 -06:00
|
|
|
// Handle termination signals (e.g., Ctrl+C)
|
|
|
|
|
signalChannel := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
go func() {
|
|
|
|
|
sig := <-signalChannel
|
|
|
|
|
log.Info("Received signal: %s. Shutting down...", sig)
|
|
|
|
|
broker.Shutdown()
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
}()
|
2024-12-16 15:34:44 -06:00
|
|
|
|
2025-02-22 17:25:00 -06:00
|
|
|
// Start the broker
|
|
|
|
|
broker.Startup()
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 13:38:22 -08:00
|
|
|
rootCmd.Flags().StringVar(&config.PubSubUrl, "pubsub-url", "nats://localhost:4222", "Hanzo PubSub server URL")
|
|
|
|
|
rootCmd.Flags().StringVar(&config.PubSubCredFile, "pubsub-creds", "", "Hanzo PubSub credentials file")
|
|
|
|
|
rootCmd.Flags().IntVar(&config.BrokerPort, "port", 9092, "Kafka listener port")
|
2026-02-23 16:23:28 -08:00
|
|
|
rootCmd.Flags().IntVar(&config.AdminPort, "admin-port", 9093, "Admin HTTP port (0 to disable)")
|
2026-02-22 13:38:22 -08:00
|
|
|
rootCmd.Flags().StringVar(&config.BrokerHost, "host", "localhost", "Advertised hostname")
|
|
|
|
|
rootCmd.Flags().IntVar(&config.NodeID, "node-id", 1, "Broker node ID")
|
|
|
|
|
rootCmd.Flags().IntVar(&config.StreamReplicas, "replicas", 1, "Hanzo Stream replica count")
|
|
|
|
|
rootCmd.Flags().StringVar(&config.StorageType, "storage", "file", "Hanzo Stream storage type: file or memory")
|
|
|
|
|
|
2025-02-22 17:25:00 -06:00
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
|
|
|
log.Panic("Failed to execute root command %v", err)
|
|
|
|
|
}
|
2024-12-16 15:34:44 -06:00
|
|
|
}
|