Files
s3/weed/command/mq_kafka_gateway.go
zooqueen dd74d3e6d6 Replace AGPL MinIO fork with Apache-2.0 SeaweedFS fork; rebrand CLI weed->s3
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.

- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
  "Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
  SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
  (replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
  keep their upstream import paths with zero churn. Internal identifiers and
  import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
  help/usage/flag strings, shell autocomplete program name, and the product name
  in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
  (e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
  `cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
  updated to ignore the `s3` build output.
2026-06-18 23:41:25 -07:00

144 lines
5.8 KiB
Go

package command
import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/mq/kafka/gateway"
"github.com/seaweedfs/seaweedfs/weed/util"
)
var (
mqKafkaGatewayOptions mqKafkaGatewayOpts
)
type mqKafkaGatewayOpts struct {
ip *string
ipBind *string
port *int
pprofPort *int
master *string
filerGroup *string
schemaRegistryURL *string
defaultPartitions *int
}
func init() {
cmdMqKafkaGateway.Run = runMqKafkaGateway
mqKafkaGatewayOptions.ip = cmdMqKafkaGateway.Flag.String("ip", util.DetectedHostAddress(), "Kafka gateway advertised host address")
mqKafkaGatewayOptions.ipBind = cmdMqKafkaGateway.Flag.String("ip.bind", "", "Kafka gateway bind address (default: same as -ip)")
mqKafkaGatewayOptions.port = cmdMqKafkaGateway.Flag.Int("port", 9092, "Kafka gateway listen port")
mqKafkaGatewayOptions.pprofPort = cmdMqKafkaGateway.Flag.Int("port.pprof", 0, "HTTP profiling port (0 to disable)")
mqKafkaGatewayOptions.master = cmdMqKafkaGateway.Flag.String("master", "localhost:9333", "comma-separated Hanzo S3 master servers")
mqKafkaGatewayOptions.filerGroup = cmdMqKafkaGateway.Flag.String("filerGroup", "", "filer group name")
mqKafkaGatewayOptions.schemaRegistryURL = cmdMqKafkaGateway.Flag.String("schema-registry-url", "", "Schema Registry URL (required for schema management)")
mqKafkaGatewayOptions.defaultPartitions = cmdMqKafkaGateway.Flag.Int("default-partitions", 4, "Default number of partitions for auto-created topics")
}
var cmdMqKafkaGateway = &Command{
UsageLine: "mq.kafka.gateway [-ip=<host>] [-ip.bind=<bind_addr>] [-port=9092] [-master=<master_servers>] [-filerGroup=<group>] [-default-partitions=4] -schema-registry-url=<url>",
Short: "start a Kafka wire-protocol gateway for SeaweedMQ with schema management",
Long: `Start a Kafka wire-protocol gateway translating Kafka client requests to SeaweedMQ.
Connects to Hanzo S3 master servers to discover available brokers and integrates with
Schema Registry for schema-aware topic management.
Options:
-ip Advertised host address that clients should connect to (default: auto-detected)
-ip.bind Bind address for the gateway to listen on (default: same as -ip)
Use 0.0.0.0 to bind to all interfaces while advertising specific IP
-port Listen port (default: 9092)
-default-partitions Default number of partitions for auto-created topics (default: 4)
-schema-registry-url Schema Registry URL (REQUIRED for schema management)
Examples:
s3 mq.kafka.gateway -port=9092 -master=localhost:9333 -schema-registry-url=http://localhost:8081
s3 mq.kafka.gateway -ip=gateway1 -port=9092 -master=master1:9333,master2:9333 -schema-registry-url=http://schema-registry:8081
s3 mq.kafka.gateway -ip=external.host.com -ip.bind=0.0.0.0 -master=localhost:9333 -schema-registry-url=http://schema-registry:8081
This is experimental and currently supports a minimal subset for development.
`,
}
func runMqKafkaGateway(cmd *Command, args []string) bool {
// Validate required options
if *mqKafkaGatewayOptions.master == "" {
glog.Fatalf("Hanzo S3 master address is required (-master)")
return false
}
// Schema Registry URL is required for schema management
if *mqKafkaGatewayOptions.schemaRegistryURL == "" {
glog.Fatalf("Schema Registry URL is required (-schema-registry-url)")
return false
}
// Determine bind address - default to advertised IP if not specified
bindIP := *mqKafkaGatewayOptions.ipBind
if bindIP == "" {
bindIP = *mqKafkaGatewayOptions.ip
}
// Construct listen address from bind IP and port
listenAddr := fmt.Sprintf("%s:%d", bindIP, *mqKafkaGatewayOptions.port)
// Set advertised host for Kafka protocol handler
if err := os.Setenv("KAFKA_ADVERTISED_HOST", *mqKafkaGatewayOptions.ip); err != nil {
glog.Warningf("Failed to set KAFKA_ADVERTISED_HOST environment variable: %v", err)
}
srv := gateway.NewServer(gateway.Options{
Listen: listenAddr,
Masters: *mqKafkaGatewayOptions.master,
FilerGroup: *mqKafkaGatewayOptions.filerGroup,
SchemaRegistryURL: *mqKafkaGatewayOptions.schemaRegistryURL,
DefaultPartitions: int32(*mqKafkaGatewayOptions.defaultPartitions),
})
glog.Warningf("EXPERIMENTAL FEATURE: MQ Kafka Gateway is experimental and should NOT be used in production environments. It currently supports only a minimal subset of Kafka protocol for development purposes.")
// Show bind vs advertised addresses for clarity
if bindIP != *mqKafkaGatewayOptions.ip {
glog.V(0).Infof("Starting MQ Kafka Gateway: binding to %s, advertising %s:%d to clients",
listenAddr, *mqKafkaGatewayOptions.ip, *mqKafkaGatewayOptions.port)
} else {
glog.V(0).Infof("Starting MQ Kafka Gateway on %s", listenAddr)
}
glog.V(0).Infof("Using SeaweedMQ brokers from masters: %s", *mqKafkaGatewayOptions.master)
// Start HTTP profiling server if enabled
if *mqKafkaGatewayOptions.pprofPort > 0 {
go func() {
pprofAddr := fmt.Sprintf(":%d", *mqKafkaGatewayOptions.pprofPort)
glog.V(0).Infof("Kafka Gateway pprof server listening on %s", pprofAddr)
glog.V(0).Infof("Access profiling at: http://localhost:%d/debug/pprof/", *mqKafkaGatewayOptions.pprofPort)
if err := http.ListenAndServe(pprofAddr, nil); err != nil {
glog.Errorf("pprof server error: %v", err)
}
}()
}
if err := srv.Start(); err != nil {
glog.Fatalf("mq kafka gateway start: %v", err)
return false
}
// Set up graceful shutdown
defer func() {
glog.V(0).Infof("Shutting down MQ Kafka Gateway...")
if err := srv.Close(); err != nil {
glog.Errorf("mq kafka gateway close: %v", err)
}
}()
// Serve blocks until closed
if err := srv.Wait(); err != nil {
glog.Errorf("mq kafka gateway wait: %v", err)
return false
}
return true
}