Documentation
¶
Index ¶
- Constants
- Variables
- func MarshalMessage(msg *Message) ([]byte, error)
- func RenderConfig(ctx context.Context, path string) ([]byte, error)
- func RenderConfigTo(ctx context.Context, path string, w io.Writer) error
- func RunCLI(ctx context.Context) error
- type App
- type Bridge
- type BridgeConfig
- type CLI
- type Config
- type FromConfig
- type FromRabbitMQConfig
- type FromSimpleMQConfig
- type Message
- type MessageError
- type Metrics
- type PublishResult
- type Publisher
- type RabbitMQConfig
- type RabbitMQPublisher
- type RabbitMQSubscriber
- type RenderCmd
- type RoutingKeys
- type RunCmd
- type SimpleMQConfig
- type SimpleMQPublisher
- type SimpleMQSubscriber
- type Subscriber
- type ToConfig
- type ToRabbitMQConfig
- type ToSimpleMQConfig
- type ValidateCmd
Constants ¶
const ( HeaderRabbitMQExchange = "rabbitmq.exchange" HeaderRabbitMQRoutingKey = "rabbitmq.routing_key" HeaderRabbitMQReplyTo = "rabbitmq.reply_to" HeaderRabbitMQCorrelationID = "rabbitmq.correlation_id" HeaderRabbitMQContentType = "rabbitmq.content_type" HeaderRabbitMQMessageID = "rabbitmq.message_id" // HeaderRabbitMQHeaderPrefix is used for custom AMQP headers. // e.g. an AMQP header "x-foo" becomes "rabbitmq.header.x-foo". HeaderRabbitMQHeaderPrefix = "rabbitmq.header." )
Header key constants for RabbitMQ-specific metadata.
Variables ¶
var Version = "v0.4.3"
Functions ¶
func MarshalMessage ¶ added in v0.1.0
MarshalMessage serializes a Message to JSON (for SimpleMQ transport). If the body is valid UTF-8, it is stored as a plain string. Otherwise, it is base64-encoded and body_encoding is set to "base64".
func RenderConfig ¶
RenderConfig evaluates a Jsonnet config file and returns the resulting JSON.
func RenderConfigTo ¶
RenderConfigTo evaluates a config file and writes pretty-printed JSON to w.
Types ¶
type App ¶
type App struct {
Config *Config
// contains filtered or unexported fields
}
App holds the application state.
type Bridge ¶
type Bridge struct {
From Subscriber
To []Publisher
// contains filtered or unexported fields
}
Bridge connects one Subscriber to multiple Publishers.
type BridgeConfig ¶
type BridgeConfig struct {
Name string `json:"name,omitempty"`
From FromConfig `json:"from"`
To []ToConfig `json:"to"`
}
BridgeConfig defines a single bridge rule.
type CLI ¶
type CLI struct {
Config string `kong:"required,short='c',env='MQBRIDGE_CONFIG',help='Config file path (Jsonnet/JSON)'" `
LogFormat string `kong:"default='text',enum='text,json',env='MQBRIDGE_LOG_FORMAT',help='Log format (text or json)'" `
LogLevel string `kong:"default='info',enum='debug,info,warn,error',env='MQBRIDGE_LOG_LEVEL',help='Log level (debug, info, warn, error)'" `
Run RunCmd `cmd:"" help:"Run the bridge"`
Validate ValidateCmd `cmd:"" help:"Validate config"`
Render RenderCmd `cmd:"" help:"Render config as JSON to stdout"`
Version kong.VersionFlag `help:"Show version"`
}
CLI defines the command-line interface for mqbridge.
type Config ¶
type Config struct {
RabbitMQ RabbitMQConfig `json:"rabbitmq"`
SimpleMQ SimpleMQConfig `json:"simplemq"`
Bridges []BridgeConfig `json:"bridges"`
}
Config is the top-level configuration for mqbridge.
func LoadConfig ¶
LoadConfig loads and parses a configuration file (Jsonnet or JSON).
type FromConfig ¶
type FromConfig struct {
RabbitMQ *FromRabbitMQConfig `json:"rabbitmq,omitempty"`
SimpleMQ *FromSimpleMQConfig `json:"simplemq,omitempty"`
}
FromConfig defines the source of a bridge.
type FromRabbitMQConfig ¶
type FromRabbitMQConfig struct {
RabbitMQConfig // embedded: url (overrides global)
Queue string `json:"queue"`
Exchange string `json:"exchange"`
ExchangeType string `json:"exchange_type"`
RoutingKey RoutingKeys `json:"routing_key"`
ExchangePassive bool `json:"exchange_passive"`
}
FromRabbitMQConfig defines a RabbitMQ source.
type FromSimpleMQConfig ¶
type FromSimpleMQConfig struct {
SimpleMQConfig // embedded: api_url (overrides global)
Queue string `json:"queue"`
APIKey string `json:"api_key"`
PollingInterval string `json:"polling_interval"`
}
FromSimpleMQConfig defines a SimpleMQ source.
func (*FromSimpleMQConfig) GetPollingInterval ¶
func (c *FromSimpleMQConfig) GetPollingInterval() time.Duration
GetPollingInterval returns the polling interval as a time.Duration.
type Message ¶ added in v0.1.0
type Message struct {
Body []byte
Headers map[string]string
// contains filtered or unexported fields
}
Message is the common message type passed between Subscriber and Publisher.
func UnmarshalMessage ¶ added in v0.1.0
UnmarshalMessage deserializes a Message from JSON. If body_encoding is "base64", the body is decoded from base64. If the data is not valid messageWire JSON or the body field is absent, it falls back to treating the entire data as the message body (backward compatibility).
func (*Message) MessageID ¶ added in v0.4.2
MessageID returns the message identifier. It prefers the in-memory id (e.g. SimpleMQ message ID), then falls back to the rabbitmq.message_id header. Returns empty string if neither is set.
func (*Message) RabbitMQPublishParams ¶ added in v0.1.0
func (m *Message) RabbitMQPublishParams() (exchange, routingKey string, headers map[string]string, err error)
RabbitMQPublishParams extracts RabbitMQ publishing parameters from a Message. Returns exchange, routingKey, and custom AMQP headers. Exchange may be empty (AMQP default exchange). RoutingKey may also be empty (e.g. for fanout exchanges). Both header keys must be present.
func (*Message) ValidateForRabbitMQ ¶ added in v0.1.0
ValidateForRabbitMQ checks that the message has the required headers for publishing to RabbitMQ (rabbitmq.exchange and rabbitmq.routing_key). Both keys must be present but may be empty strings.
type MessageError ¶ added in v0.1.0
type MessageError struct {
Err error
}
MessageError represents an error caused by the message content itself (e.g. missing required headers). Messages that cause this error cannot be processed regardless of retries and should be dropped.
func (*MessageError) Error ¶ added in v0.1.0
func (e *MessageError) Error() string
func (*MessageError) Unwrap ¶ added in v0.1.0
func (e *MessageError) Unwrap() error
type Metrics ¶ added in v0.0.2
type Metrics struct {
// contains filtered or unexported fields
}
Metrics holds OpenTelemetry metric instruments for mqbridge.
type PublishResult ¶ added in v0.0.2
type PublishResult struct {
Destination string // destination identifier (e.g. queue name, "exchange/routing_key")
}
PublishResult holds metadata about a published message.
type Publisher ¶
type Publisher interface {
Publish(ctx context.Context, msg *Message) (*PublishResult, error)
// Type returns the publisher type name (e.g. "rabbitmq", "simplemq").
Type() string
Close() error
}
Publisher sends messages to a destination.
type RabbitMQConfig ¶
type RabbitMQConfig struct {
URL string `json:"url"`
}
RabbitMQConfig holds the global RabbitMQ connection settings.
type RabbitMQPublisher ¶
type RabbitMQPublisher struct {
// contains filtered or unexported fields
}
RabbitMQPublisher publishes messages to RabbitMQ. The destination exchange and routing key are determined by the message JSON.
func NewRabbitMQPublisher ¶
func NewRabbitMQPublisher(config ToRabbitMQConfig, logger *slog.Logger) *RabbitMQPublisher
NewRabbitMQPublisher creates a new RabbitMQPublisher.
func (*RabbitMQPublisher) Close ¶
func (p *RabbitMQPublisher) Close() error
Close closes the RabbitMQ connection.
func (*RabbitMQPublisher) Publish ¶
func (p *RabbitMQPublisher) Publish(ctx context.Context, msg *Message) (*PublishResult, error)
Publish sends a Message to RabbitMQ. The destination exchange, routing key, and custom AMQP headers are read from the Message headers.
func (*RabbitMQPublisher) Type ¶ added in v0.0.2
func (p *RabbitMQPublisher) Type() string
Type returns the publisher type name.
type RabbitMQSubscriber ¶
type RabbitMQSubscriber struct {
// contains filtered or unexported fields
}
RabbitMQSubscriber consumes messages from a RabbitMQ queue.
func NewRabbitMQSubscriber ¶
func NewRabbitMQSubscriber(config FromRabbitMQConfig, logger *slog.Logger) *RabbitMQSubscriber
NewRabbitMQSubscriber creates a new RabbitMQSubscriber.
func (*RabbitMQSubscriber) Close ¶
func (s *RabbitMQSubscriber) Close() error
Close closes the RabbitMQ connection.
func (*RabbitMQSubscriber) Subscribe ¶
func (s *RabbitMQSubscriber) Subscribe(ctx context.Context, handler func(ctx context.Context, msg *Message) error) error
Subscribe starts consuming messages from the RabbitMQ queue with automatic reconnection on connection loss. It uses exponential backoff between retries.
type RoutingKeys ¶ added in v0.3.0
type RoutingKeys []string
RoutingKeys holds one or more routing keys. It accepts both a single string and an array of strings in JSON/Jsonnet.
func (*RoutingKeys) UnmarshalJSON ¶ added in v0.3.0
func (rk *RoutingKeys) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler. It accepts both a single string ("key") and an array (["key1", "key2"]).
type SimpleMQConfig ¶
type SimpleMQConfig struct {
APIURL string `json:"api_url"`
}
SimpleMQConfig holds the global SimpleMQ settings.
type SimpleMQPublisher ¶
type SimpleMQPublisher struct {
// contains filtered or unexported fields
}
SimpleMQPublisher sends messages to a SimpleMQ queue.
func NewSimpleMQPublisher ¶
func NewSimpleMQPublisher(config ToSimpleMQConfig) (*SimpleMQPublisher, error)
NewSimpleMQPublisher creates a new SimpleMQPublisher.
func (*SimpleMQPublisher) Close ¶
func (p *SimpleMQPublisher) Close() error
Close is a no-op for SimpleMQPublisher.
func (*SimpleMQPublisher) Publish ¶
func (p *SimpleMQPublisher) Publish(ctx context.Context, msg *Message) (*PublishResult, error)
Publish sends a Message to the SimpleMQ queue. The Message is serialized to JSON and then base64-encoded before sending.
func (*SimpleMQPublisher) Type ¶ added in v0.0.2
func (p *SimpleMQPublisher) Type() string
Type returns the publisher type name.
type SimpleMQSubscriber ¶
type SimpleMQSubscriber struct {
// contains filtered or unexported fields
}
SimpleMQSubscriber receives messages from a SimpleMQ queue via polling.
func NewSimpleMQSubscriber ¶
func NewSimpleMQSubscriber(config FromSimpleMQConfig, logger *slog.Logger) (*SimpleMQSubscriber, error)
NewSimpleMQSubscriber creates a new SimpleMQSubscriber.
func (*SimpleMQSubscriber) Close ¶
func (s *SimpleMQSubscriber) Close() error
Close is a no-op for SimpleMQSubscriber (HTTP client needs no explicit close).
type Subscriber ¶
type Subscriber interface {
Subscribe(ctx context.Context, handler func(ctx context.Context, msg *Message) error) error
Close() error
}
Subscriber consumes messages from a source.
type ToConfig ¶
type ToConfig struct {
RabbitMQ *ToRabbitMQConfig `json:"rabbitmq,omitempty"`
SimpleMQ *ToSimpleMQConfig `json:"simplemq,omitempty"`
}
ToConfig defines a destination of a bridge.
type ToRabbitMQConfig ¶
type ToRabbitMQConfig struct {
RabbitMQConfig // embedded: url (overrides global)
}
ToRabbitMQConfig defines a RabbitMQ destination. The actual exchange/routing_key/headers are determined by the message JSON.
type ToSimpleMQConfig ¶
type ToSimpleMQConfig struct {
SimpleMQConfig // embedded: api_url (overrides global)
Queue string `json:"queue"`
APIKey string `json:"api_key"`
}
ToSimpleMQConfig defines a SimpleMQ destination.