Files
zeekay 2ed73972da Bound topic partitions by age and size
Partition streams were created with no limit, so every topic grew for
as long as the store lived.  Give each one a max age and a max size,
dropping the oldest records first as Kafka does: 7 days, Kafka's own
default, and 256 MiB, since JetStream reserves each stream's byte cap
against a store sized from free disk.

At boot, bound the partitions an older broker left unlimited.  A
partition with any limit of its own is left alone.

Claude-Session: https://claude.ai/code/session_01TUxvfuta1Z44KVNYuAz71F
2026-09-24 09:27:41 -07:00

62 lines
2.1 KiB
Go

package main
import (
"os"
"os/signal"
"syscall"
log "github.com/hanzoai/kafka/logging"
"github.com/hanzoai/kafka/protocol"
"github.com/hanzoai/kafka/types"
"github.com/spf13/cobra"
)
var config = types.Configuration{
PubSubUrl: "nats://localhost:4222",
BrokerHost: "localhost",
BrokerPort: 9092,
AdminPort: 9093,
NodeID: 1,
StreamReplicas: 1,
StorageType: "file",
}
func main() {
var rootCmd = &cobra.Command{
Use: "hanzo-kafka",
Short: "Hanzo Kafka — Kafka wire protocol gateway for Hanzo PubSub",
Run: func(cmd *cobra.Command, args []string) {
broker := protocol.NewBroker(&config)
log.SetLogLevel(log.INFO)
// 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)
}()
// Start the broker
broker.Startup()
},
}
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")
rootCmd.Flags().IntVar(&config.AdminPort, "admin-port", 9093, "Admin HTTP port (0 to disable)")
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 Kafka replica count")
rootCmd.Flags().StringVar(&config.StorageType, "storage", "file", "Hanzo Kafka storage type: file or memory")
rootCmd.Flags().DurationVar(&config.RetentionMaxAge, "retention", types.DefaultRetentionMaxAge, "Partition max age (negative: no limit)")
rootCmd.Flags().Int64Var(&config.RetentionMaxBytes, "retention-bytes", types.DefaultRetentionMaxBytes, "Partition max bytes (negative: no limit)")
if err := rootCmd.Execute(); err != nil {
log.Panic("Failed to execute root command %v", err)
}
}