Documentation ¶
Overview ¶
Package carrot provides a nice API for dealing with AMQP connections.
Carrot is split in 3 separate components: topology declarator, incoming messages listener and messages handler.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultShutdownOptions = Shutdown{ Timeout: 1 * time.Minute, Signals: []os.Signal{os.Interrupt}, OnError: func(err error) { panic(err) }, }
DefaultShutdownOptions are the default Shutdown options used in case no overriding options are specified in WithGracefulShutdown.
var ErrNoConnection = errors.New("carrot: no connection provided")
ErrNoConnection is returned by Runner.Run when no valid AMQP connection has been specified.
var ErrNoHandler = errors.New("carrot: no handler specified")
ErrNoHandler is returned by Runner.Run when no handler has been specified, so that Runner.Run can't handle any incoming messages.
var ErrNoListener = errors.New("carrot: no listener specified")
ErrNoListener is returned by Runner.Run when no delivery listener has been specified, so that Runner.Run can't receive any messages from the AMQP broker.
Functions ¶
This section is empty.
Types ¶
type Closer ¶
type Closer struct {
// contains filtered or unexported fields
}
Closer allows to close the amqp.Connection provided and any active Listener after Runner.Run has called.
func Run ¶ added in v0.1.1
func Run(conn listener.Connection, options ...Option) (Closer, error)
Run is a convenience method to run a new Runner instance directly.
It is the equivalent of carrot.From(...).Run()
type Option ¶
type Option func(*Runner)
Option represents an additional argument for the Runner factory method.
func WithGracefulShutdown ¶
WithGracefulShutdown enables graceful shutdown after certain signals are received by the process.
Use WithGracefulShutdown(nil) to use the default options, which can be found in DefaultShutdownOptions.
func WithHandler ¶
WithHandler specifies the component in charge of handling incoming messages for the new Runner instance.
func WithListener ¶
WithListener specifies the component in charge of start listening messages coming from the AMQP broker.
func WithTopology ¶
WithTopology adds a topology declaration step to the new Runner instance.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner instruments all the different parts of the go-carrot library, provided with a valid AMQP connection.
func From ¶
func From(conn listener.Connection, options ...Option) Runner
From creates a new Runner instance, given an AMQP connection and options.
Required options are WithListener, to bind a channel to an amqp.Delivery sink and start receiving messages, and WithHandler, to handle all the incoming messages.
Example ¶
From(nil, WithTopology(topology.All( exchange.Declare("orders", exchange.Kind(kind.Topic), exchange.Durable, ), exchange.Declare("orders-internal", exchange.Kind(kind.Topic), exchange.Durable, ), queue.Declare( "my-service.order.invalidate", queue.BindTo("orders", "*.order.changed"), queue.Durable, queue.DeadLetterWithQueue( "orders", "my-service.order.invalidate.dead", queue.Declare( "my-service.order.invalidate.failed", queue.Durable, queue.NoWait, ), ), ), queue.Declare( "my-service.order.finalized", queue.BindTo("orders", "*.order.finalized"), queue.Durable, queue.DeadLetterWithQueue( "orders", "my-service.order.finalized.dead", queue.Declare("my-service.order.finalized.failed"), ), ), )), WithListener(consumer.Listen( "my-service.order.invalidate", consumer.Title("Invalidate Order"), )), WithHandler(router.New().Group(func(r router.Router) { r.Use(middleware.SessionPerRequest(nil)) r.Bind("my-service.order.invalidate", handler.Func(func(context.Context, amqp.Delivery) error { return nil })) })), ).Run()
Output:
func (Runner) Run ¶
Run starts all the different parts of the Runner instrumentator, in the following order: topology declaration, delivery listener and messages listener.
Message listener uses the sink channel coming from the delivery listener, and spawns a separate worker goroutine to run the message handler specified during configuration with the new amqp.Delivery received.
An error is returned if the supplied parameters during configuration are not valid, or if something happened on the AMQP connection.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
Package handler contains the reference interface for a message handler.
|
Package handler contains the reference interface for a message handler. |
router
Package router contains a Router interface and Mux, message handler multiplexer, to allow for multiple message handlers to be assigned to multiple queues.
|
Package router contains a Router interface and Mux, message handler multiplexer, to allow for multiple message handlers to be assigned to multiple queues. |
Package topology contains the reference interface for declaring the topology used by the application through an AMQP connection.
|
Package topology contains the reference interface for declaring the topology used by the application through an AMQP connection. |
exchange
Package exchange adds a topology.Declarer interface able to describe AMQP exchanges.
|
Package exchange adds a topology.Declarer interface able to describe AMQP exchanges. |
exchange/kind
Package kind contains all supported AMQP exchange kinds.
|
Package kind contains all supported AMQP exchange kinds. |
queue
Package queue adds a topology.Declarer interface able to describe AMQP queues.
|
Package queue adds a topology.Declarer interface able to describe AMQP queues. |