Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// ForwarderTopic is a topic on which the forwarder will be listening to enveloped messages to forward.
// Defaults to `forwarder_topic`.
ForwarderTopic string
// Middlewares are used to decorate forwarder's handler function.
Middlewares []message.HandlerMiddleware
// CloseTimeout determines how long router should work for handlers when closing.
CloseTimeout time.Duration
// AckWhenCannotUnwrap enables acking of messages which cannot be unwrapped from an envelope.
AckWhenCannotUnwrap bool
// Router is a router used by the forwarder.
// If not provided, a new router will be created.
//
// If router is provided, it's not necessary to call `Forwarder.Run()` if the router is started with `router.Run()`.
Router *message.Router
// Marshaler is used to deserialize envelopes received on ForwarderTopic.
// It must match the Marshaler used by the decorated Publisher.
// Defaults to DefaultMarshaler, which uses encoding/json.
Marshaler Marshaler
}
type DefaultMarshaler ¶ added in v1.5.2
type DefaultMarshaler struct{}
DefaultMarshaler uses the standard library's encoding/json package.
type Forwarder ¶
type Forwarder struct {
// contains filtered or unexported fields
}
Forwarder subscribes to the topic provided in the config and publishes them to the destination topic embedded in the enveloped message.
func NewForwarder ¶
func NewForwarder( subscriberIn message.Subscriber, publisherOut message.Publisher, logger watermill.LoggerAdapter, config Config, ) (*Forwarder, error)
NewForwarder creates a forwarder which will subscribe to the topic provided in the config using the provided subscriber. It will publish messages received on this subscription to the destination topic embedded in the enveloped message using the provided publisher.
Provided subscriber and publisher can be from different Watermill Pub/Sub implementations, i.e. MySQL subscriber and Google Pub/Sub publisher.
Note: Keep in mind that by default the forwarder will nack all messages which weren't sent using a decorated publisher. You can change this behavior by passing a middleware which will ack them instead.
type Marshaler ¶ added in v1.5.2
Marshaler is used by the Forwarder Publisher to serialize the envelope sent to the forwarder topic, and by the Forwarder consumer to deserialize it.
The interface matches the signatures of encoding/json's Marshal and Unmarshal, so any drop-in JSON library (e.g. github.com/bytedance/sonic, github.com/goccy/go-json) can be adapted with a small wrapper.
The default is DefaultMarshaler, which uses encoding/json.
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher changes `Publish` method behavior so it wraps a sent message in an envelope and sends it to the forwarder topic provided in the config.
func NewPublisher ¶
func NewPublisher(publisher message.Publisher, config PublisherConfig) *Publisher
type PublisherConfig ¶
type PublisherConfig struct {
// ForwarderTopic is a topic which the forwarder is listening to. Publisher will send enveloped messages to this topic.
// Defaults to `forwarder_topic`.
ForwarderTopic string
// Marshaler is used to serialize envelopes sent to ForwarderTopic.
// It must match the Marshaler used by the Forwarder consuming the topic.
// Defaults to DefaultMarshaler, which uses encoding/json.
Marshaler Marshaler
}
PublisherConfig configures the decorating Publisher returned by NewPublisher.
func (*PublisherConfig) Validate ¶
func (c *PublisherConfig) Validate() error