peake100/rogerRabbit-go

View on GitHub
pkg/amqp/config.go

Summary

Maintainability
A
0 mins
Test Coverage
package amqp

import (
    "crypto/tls"
    "github.com/rs/zerolog"
    "net"
    "time"
)

// Config is used in DialConfig and Open to specify the desired tuning
// parameters used during a connection open handshake.  The negotiated tuning
// will be stored in the returned connection's Config field.
//
// ---
//
// ROGER NOTE: This config type is a re-implementation of streadway/amqp.Config. We
// any code that can declare such a config will work with this type. In the future this
// type may add additional options for rogerRabbit-go/amqp.
type Config struct {
    // The SASL mechanisms to try in the client request, and the successful
    // mechanism used on the Connection object.
    // If SASL is nil, PlainAuth from the URL is used.
    SASL []Authentication

    // Vhost specifies the namespace of permissions, exchanges, queues and
    // bindings on the server. Dial sets this to the path parsed from the URL.
    Vhost string

    ChannelMax int           // 0 max channels means 2^16 - 1
    FrameSize  int           // 0 max bytes means unlimited
    Heartbeat  time.Duration // less than 1s uses the server's interval

    // TLSClientConfig specifies the client configuration of the TLS connection
    // when establishing a tls livesOnce.
    // If the URL uses an amqps scheme, then an empty tls.Config with the
    // ServerName from the URL is used.
    TLSClientConfig *tls.Config

    // Properties is table of properties that the client advertises to the server.
    // This is an optional setting - if the application does not set this,
    // the underlying library will use a generic set of client properties.
    Properties Table

    // Connection locale that we expect to always be en_US
    // Even though servers must return it as per the AMQP 0-9-1 spec,
    // we are not aware of it being used other than to satisfy the spec requirements
    Locale string

    // Dial returns a net.Conn prepared for a TLS handshake with TSLClientConfig,
    // then an AMQP connection handshake.
    // If Dial is nil, net.DialTimeout with a 30s connection and 30s deadline is
    // used during TLS and AMQP handshaking.
    Dial func(network, addr string) (net.Conn, error)

    // If set to true, the default handlers will not be registered on connection or
    // channels created as a result of passing this config.
    NoDefaultMiddleware bool

    // DefaultLoggerLevel is the logger level for the default logging middleware.
    //
    // If NoDefaultMiddleware is true, this setting will have no effect.
    //
    // Default: zerolog.InfoLevel.
    DefaultLoggerLevel zerolog.Level

    // ConnectionMiddleware holds middleware to add to connection method and event
    // handlers.
    ConnectionMiddleware ConnectionMiddlewares

    // ChannelMiddleware holds middleware to add to channel method and event handlers.
    ChannelMiddleware ChannelMiddlewares
}

// DefaultConfig returns the default config for Dial() as it is in the streadway
// application.
func DefaultConfig() Config {
    return Config{
        Heartbeat:          defaultHeartbeat,
        Locale:             defaultLocale,
        DefaultLoggerLevel: zerolog.ErrorLevel,
    }
}