Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AMQP ¶
type AMQP struct {
// contains filtered or unexported fields
}
type Broker ¶
type Broker interface { // Consumer create new consumer instance Consumer(exchange *types.Exchange, queue *types.Queue, consumer *types.Consumer, routingKeys []*types.RoutingKey, messageHandler types.ConsumerHandler, options ...ConsumerOptions) (Consumer, error) // Publisher create a publisher instance Publisher(exchange *types.Exchange, confirmMode bool, options ...PublisherOption) (Publisher, error) // Close rabbitmq connection Close() error }
type Consumer ¶
type Consumer interface { // Start consumer for consume messages Start() error // Close close consumer Close() }
type ConsumerOptions ¶
type ConsumerOptions func(options *consumerOptions)
func EnableQOSGlobal ¶
func EnableQOSGlobal(enable bool) ConsumerOptions
EnableQOSGlobal which means these QOS settings apply to ALL existing and future consumers on all channels on the same connection
func WithConcurrentConsumer ¶
func WithConcurrentConsumer(concurrent int) ConsumerOptions
WithConcurrentConsumer many goroutines will be spawned to run the provided handler on messages
func WithCustomQOSPrefetch ¶
func WithCustomQOSPrefetch(prefetch int) ConsumerOptions
WithCustomQOSPrefetch which means that many messages will be fetched from the server in advance to help with throughput. This doesn't affect the handler, messages are still processed one at a time.
type Publisher ¶
type Publisher interface { /* Publish sends a Publishing from the client to an exchange on the server. When you want a single message to be delivered to a single queue, you can publish to the default exchange with the routingKey of the queue name. This is because every declared queue gets an implicit route to the default exchange. Since publishings are asynchronous, any undeliverable message will get returned by the server. Add a listener with Channel.NotifyReturn to handle any undeliverable message when calling publish with either the mandatory or immediate parameters as true. Publishings can be undeliverable when the mandatory flag is true and no queue is bound that matches the routing key, or when the immediate flag is true and no consumer on the matched queue is ready to accept the delivery. This can return an error when the channel, connection or socket is closed. The error or lack of an error does not indicate whether the server has received this publishing. It is possible for publishing to not reach the broker if the underlying socket is shut down without pending publishing packets being flushed from the kernel buffers. The easy way of making it probable that all publishings reach the server is to always call Connection.Close before terminating your publishing application. The way to ensure that all publishings reach the server is to add a listener to Channel.NotifyPublish and put the channel in confirm mode with Channel.Confirm. Publishing delivery tags and their corresponding confirmations startConsume at 1. Exit when all publishings are confirmed. When Publish does not return an error and the channel is in confirm mode, the internal counter for DeliveryTags with the first confirmation starts at 1. Note: routingKey is specific keys in queue for example (subject, topic) */ Publish( mandatory bool, immediate bool, msg types.Publishing, routingKeys ...string, ) error /* PublishWithContext sends a Publishing from the client to an exchange on the server and control by prent context. When you want a single message to be delivered to a single queue, you can publish to the default exchange with the routingKey of the queue name. This is because every declared queue gets an implicit route to the default exchange. Since publishings are asynchronous, any undeliverable message will get returned by the server. Add a listener with Channel.NotifyReturn to handle any undeliverable message when calling publish with either the mandatory or immediate parameters as true. Publishings can be undeliverable when the mandatory flag is true and no queue is bound that matches the routing key, or when the immediate flag is true and no consumer on the matched queue is ready to accept the delivery. This can return an error when the channel, connection or socket is closed. The error or lack of an error does not indicate whether the server has received this publishing. It is possible for publishing to not reach the broker if the underlying socket is shut down without pending publishing packets being flushed from the kernel buffers. The easy way of making it probable that all publishings reach the server is to always call Connection.Close before terminating your publishing application. The way to ensure that all publishings reach the server is to add a listener to Channel.NotifyPublish and put the channel in confirm mode with Channel.Confirm. Publishing delivery tags and their corresponding confirmations startConsume at 1. Exit when all publishings are confirmed. When Publish does not return an error and the channel is in confirm mode, the internal counter for DeliveryTags with the first confirmation starts at 1. Note: routingKey is specific keys in queue for example (subject, topic) */ PublishWithContext( ctx context.Context, mandatory bool, immediate bool, msg types.Publishing, routingKeys ...string, ) error // PublishWithDeferredConfirmWithContext publishes the provided data to the given routing keys over the connection. // if the publisher is in confirm mode (which can be either done by calling `NotifyPublish` with a custom handler // or by using `WithPublisherOptionsConfirm`) a publisher confirmation is returned. // This confirmation can be used to check if the message was actually published or wait for this to happen. // If the publisher is not in confirm mode, the returned confirmation will always be nil. PublishWithDeferredConfirmWithContext( ctx context.Context, mandatory bool, immediate bool, msg types.Publishing, routingKeys ...string, ) (types.PublisherConfirmation, error) // PublishWithRetry sends a Publishing from the client to an exchange on the server, // controlled by the provided context. It incorporates a retry mechanism, attempting // to publish the message multiple times with a configurable delay and maximum number // of retries. // // When you want a single message to be delivered to a specific queue, you can publish // to the default exchange with the routingKey set to the queue name. This is because // every declared queue gets an implicit route to the default exchange. // // Since publishings are asynchronous, any undeliverable message will be returned by // the server. Add a listener with Channel.NotifyReturn to handle undeliverable // messages when calling publish with either the mandatory or immediate parameters as true. // // Publishings can be undeliverable when the mandatory flag is true and no queue is // bound that matches the routing key, or when the immediate flag is true and no // consumer on the matched queue is ready to accept the delivery. // // This function may return an error when the channel, connection, or socket is closed. // The error, or lack of an error, does not indicate whether the server has received this // publishing. // // It is possible for publishing to not reach the broker if the underlying socket // is shut down without pending publishing packets being flushed from the kernel // buffers. To increase the likelihood that all publishings reach the server, it is // recommended to always call Connection.Close before terminating your publishing // application. Alternatively, add a listener to Channel.NotifyPublish and put the channel // in confirm mode with Channel.Confirm. Publishing delivery tags and their corresponding // confirmations start at 1. Exit when all publishings are confirmed. // // When PublishWithRetry does not return an error and the channel is in confirm mode, // the internal counter for DeliveryTags with the first confirmation starts at 1. // // Note: routingKey represents specific keys in the queue, such as subject or topic. PublishWithRetry( ctx context.Context, mandatory bool, immediate bool, msg types.Publishing, config types.PublisherConfig, routingKeys ...string, ) error // NotifyReturn registers a listener for basic.return methods. // These can be sent from the server when a publish is undeliverable either from the mandatory or immediate flags. // These notifications are shared across an entire connection, so if you're creating multiple // publishers on the same connection keep that in mind NotifyReturn(handler func(r types.Return)) // NotifyPublish registers a listener for publish confirmations, must set ConfirmPublishings option // These notifications are shared across an entire connection, so if you're creating multiple // publishers on the same connection keep that in mind NotifyPublish(handler func(p types.Confirmation)) Close() }
type PublisherOption ¶ added in v1.2.3
type PublisherOption func(options *publisherOptions)
func WithAutoMessageID ¶ added in v1.2.3
func WithAutoMessageID() PublisherOption
WithAutoMessageID set uuid for message on publishing
func WithAutoTimestamp ¶ added in v1.2.3
func WithAutoTimestamp() PublisherOption
WithAutoTimestamp set timestamp in message on publishing
type RabbitMQOptions ¶
type RabbitMQOptions func(*rabbitMQOptions)
func ReconnectDelay ¶
func ReconnectDelay(delay time.Duration) RabbitMQOptions
func WithCustomAMQPConfig ¶
func WithCustomAMQPConfig(config amqp.Config) RabbitMQOptions
func WithCustomEncoder ¶ added in v1.2.1
func WithCustomEncoder(encType types.EncodeType) RabbitMQOptions
WithCustomEncoder change default encoder to another encoder (JSON, GOB, ProtoBuf)
Note: if you change default encoder form publisher or consumer, both match encoder (encode and decode)
func WithCustomLogger ¶ added in v1.1.0
func WithCustomLogger(logger logger.Logger) RabbitMQOptions