GoWindGoWind
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
Home
Framework
GoWind Toolkit
  • Open Source

    • GoWind Admin (Admin Platform)
    • GoWind CMS (Content Management)
    • GoWind UBA (Behavior Analytics)
    • GoWind Shop (E-commerce)
    • GoWind Kanban (Kanban Boards)
    • GoWind Ledger (Personal Finance)
    • GoWind ShortPlay (Short Drama)
    • GoWind Ops (Operations Platform)
    • RushWind (Rust Ecosystem)
  • Open Core (Community + Enterprise)

    • GoWind OA (Office Collaboration)
    • GoWind ERP (Procure-to-Pay)
    • GoWind WMS (Warehousing)
  • Commercial

    • GoWind IM (Instant Messaging)
    • GoWind IoT (IoT Platform)
    • GoWind Edu (AI Education)
    • GoWind MES (Manufacturing Execution)
    • GoWind CDC (Data Pipeline)
    • GoWind SDP (Zero-Trust Gateway)
    • GoWind Quant (Quant Research)
    • GoWind Trade Radar (Export Sourcing)
    • GoWind Game Radar (Game Greenlight)
  • 简体中文
  • English
GitHub
  • Introduction

    • GoWind Framework
    • Framework Architecture
  • go-wind Core

    • go-wind Core Framework
    • App Lifecycle Management
    • Context Propagation
    • Transport Abstraction
    • Log Facade Interface
  • go-wind-plugins

    • go-wind-plugins Plugin Overview
    • Plugin Configuration System
    • Plugin Registration Mechanism (SPI)
    • Logging Adapter Plugins
    • Transport Protocol Plugins
    • Message Middleware Plugins
    • Encoding Plugins
    • Security and Authentication Plugins
    • Distributed Tracing Plugins
    • Cache Plugins
    • Object Storage Plugins (OSS)
    • Rate Limiting Plugins
    • Metrics Plugins
    • AI Plugins
    • Workflow Plugins
    • Database and Cache Plugins
    • Bootstrap Integration and Gateway Plugins
    • Compression and Serialization Plugins
    • Template Rendering and Validation Plugins
  • go-wind-bootstrap

    • go-wind-bootstrap: The Declarative Bootstrap
    • The Bootstrap Configuration System
    • The Bootstrap SPI Mechanism
    • Declarative Middleware Orchestration
    • Bootstrap Command-Line Integration
    • Bootstrap Practical Examples
  • go-wind-flow Workflow Engine

    • GoWind Flow Process Engine
  • Tutorials

    • Quick Start Tutorial
    • Custom Plugin Development Tutorial
    • Multi-Protocol Listening Tutorial
    • Framework Migration Guide

Message Middleware Plugins

go-wind-plugins provides a variety of message queue (Broker) adapters behind the unified broker.Broker interface, supporting publish/subscribe and Request/Reply request-response patterns.

1. The Broker Interface

type Broker interface {
    Name() string
    Options() Options
    Address() string

    Init(...Option) error
    Connect() error
    Disconnect() error

    Publish(ctx context.Context, topic string, msg *Message, opts ...PublishOption) error
    Subscribe(topic string, handler Handler, binder Binder, opts ...SubscribeOption) (Subscriber, error)

    // Request sends a request message and waits for a response
    Request(ctx context.Context, topic string, msg *Message, opts ...RequestOption) (*Message, error)
}

type Message struct {
    ID      string
    Headers Headers          // map[string]string
    Body    any              // serialized by the codec registered via WithCodec
    Key     string           // Kafka Key / RocketMQ Key / RabbitMQ RoutingKey...
    Metadata Metadata
}

Beyond the native Subscribe, a generic subscription helper broker.Subscribe[T] (with automatic payload deserialization), a generic TypedHandler, and publish/subscribe middleware chains (WithPublishMiddlewares / WithSubscriberMiddlewares) are also provided.

2. Adapter List

AdapterImport PathEngine
Kafkaplugins/broker/kafkasegmentio/kafka-go
RabbitMQplugins/broker/rabbitmqrabbitmq/amqp091-go
NATSplugins/broker/natsnats-io/nats.go (JetStream)
MQTTplugins/broker/mqtteclipse/paho.mqtt.golang
Pulsarplugins/broker/pulsarapache/pulsar-client-go
Redisplugins/broker/redisgomodule/redigo
RocketMQplugins/broker/rocketmqapache/rocketmq-client-go + rocketmq-clients
NSQplugins/broker/nsqnsqio/go-nsq
SQSplugins/broker/sqsaws/aws-sdk-go-v2
GCP Pub/Subplugins/broker/gcpubsubcloud.google.com/go/pubsub
Azure Service Busplugins/broker/azuresbazure-sdk-for-go
STOMPplugins/broker/stompgo-stomp/stomp

The engine SDKs differ considerably, so each sub-module defines its own configuration options, but all implement the core broker.Broker interface; common options (WithAddress / WithCodec / WithTLSConfig / WithTracerProvider / middleware, etc.) are provided uniformly by the family.

3. Kafka

import (
    "github.com/tx7do/go-wind-plugins/broker"
    kafkaPlugin "github.com/tx7do/go-wind-plugins/broker/kafka"
)

b := kafkaPlugin.NewBroker(
    broker.WithAddress("localhost:9092"),
    broker.WithCodec("json"),
)

_ = b.Init()
_ = b.Connect()
defer b.Disconnect()

Publishing Messages

msg := broker.NewMessage(
    map[string]any{"event": "user_login", "user_id": "123"},
    broker.WithPublishHeaders(map[string]string{
        "trace_id": traceID,
    }),
)

b.Publish(ctx, "user-events", msg)

Subscribing to Messages

sub, _ := b.Subscribe("user-events",
    func(ctx context.Context, event broker.Event) error {
        fmt.Println(event.Topic(), event.Message().Body)
        return nil  // returning nil ACKs automatically
    },
    func() any { return &map[string]any{} },  // Binder
)

YAML Configuration

broker:
  kafka:
    addrs: ["localhost:9092"]
    group_id: "my-service"
    version: "3.0.0"
    topics:
      - name: user-events
        partitions: 6
        replication: 3
    consumer:
      initial_offset: latest    # latest | earliest
      session_timeout: 10s
      rebalance_timeout: 30s
    producer:
      acks: all                 # none | one | all
      compression: snappy       # none | gzip | snappy | lz4 | zstd
      batch_size: 16384

4. RabbitMQ

import (
    "github.com/tx7do/go-wind-plugins/broker"
    rabbitmqPlugin "github.com/tx7do/go-wind-plugins/broker/rabbitmq"
)

b := rabbitmqPlugin.NewBroker(
    broker.WithAddress("amqp://guest:guest@localhost:5672/"),
    rabbitmqPlugin.WithExchangeName("events"),
    rabbitmqPlugin.WithExchangeType("topic"),
    rabbitmqPlugin.WithDurableExchange(),
    rabbitmqPlugin.WithPrefetchCount(10),   // prefetch count
)

YAML Configuration

broker:
  rabbitmq:
    addrs: ["amqp://guest:guest@localhost:5672/"]
    exchange: events
    exchange_type: topic
    durable: true
    auto_delete: false
    qos:
      prefetch_count: 10
      prefetch_global: false
    queues:
      - name: order-events
        routing_key: order.*
        durable: true

5. NATS

import (
    "github.com/tx7do/go-wind-plugins/broker"
    natsPlugin "github.com/tx7do/go-wind-plugins/broker/nats"
)

b := natsPlugin.NewBroker(
    broker.WithAddress("nats://localhost:4222"),
    broker.WithCodec("json"),
)

// JetStream subscription: declare the Durable name and delivery policy
sub, _ := b.Subscribe("events",
    handler,
    binder,
    broker.WithSubscribeQueueName("my-service"),
    natsPlugin.WithDurable("my-durable"),
    natsPlugin.WithDeliverAll(),
)

YAML Configuration

broker:
  nats:
    addrs: ["nats://localhost:4222"]
    jetstream: true
    max_reconnects: 60
    reconnect_wait: 2s
    credentials_file: nats.creds

6. Redis Pub/Sub

import (
    "github.com/tx7do/go-wind-plugins/broker"
    redisBrokerPlugin "github.com/tx7do/go-wind-plugins/broker/redis"
)

b := redisBrokerPlugin.NewBroker(
    broker.WithAddress("localhost:6379"),
    broker.WithCodec("json"),
    redisBrokerPlugin.WithPassword("pass"),
)

// Streams consumer group (optional)
_ = b.Subscribe("events", handler, binder,
    redisBrokerPlugin.WithStreamGroup("my-group"),
    redisBrokerPlugin.WithStreamConsumer("consumer-1"),
)

YAML Configuration

broker:
  redis:
    addr: localhost:6379
    db: 1
    channels:
      - events
      - notifications
    buffer_size: 1000

7. Selection Guide

RequirementRecommendation
Log/event streamsKafka (high throughput, persistence)
Task queuesRabbitMQ (ACK, routing)
Internal microservice messagingNATS (low latency)
Simple pub/subRedis (no extra dependencies)
IoT device messagingMQTT (lightweight, QoS)
Financial/transactional messagingRocketMQ (transactional messages)
Large-scale stream processingPulsar (multi-tenancy)
Managed cloud queuesSQS / GCP Pub/Sub / Azure Service Bus
Enterprise message bus integrationSTOMP

8. Combining Multiple Brokers

broker:
  kafka:          # primary event stream
    addrs: ["localhost:9092"]
    group_id: "event-processor"
  rabbitmq:       # task queue
    addrs: ["amqp://localhost:5672/"]
    exchange: tasks
  redis:          # notification broadcast
    addr: localhost:6379
    channels:
      - notifications
import (
    _ "github.com/tx7do/go-wind-plugins/broker/kafka"
    _ "github.com/tx7do/go-wind-plugins/broker/rabbitmq"
    _ "github.com/tx7do/go-wind-plugins/broker/redis"
)

Related Documents

  • Plugin Configuration System
  • Plugin Overview
  • Encoding Plugins
Edit this page
Last Updated:: 11/3/26, 2:14 PM
Contributors: Bobo
Prev
Transport Protocol Plugins
Next
Encoding Plugins