Documentation
¶
Index ¶
- func InitializeContext(ctx context.Context) context.Context
- type ContextKey
- type Logger
- type Session
- func (s *Session) ConfigureConnection(ctx context.Context, uri string) error
- func (s *Session) ConfigureHeaders(ctx context.Context, headers map[string]interface{}) error
- func (s *Session) ConfigureStandardProperties(ctx context.Context, props amqp.Publishing)
- func (s *Session) PublishJSONMessage(ctx context.Context, topic string, props map[string]interface{}) error
- func (s *Session) PublishTextMessage(ctx context.Context, topic, message string) error
- func (s *Session) SubscribeTopic(ctx context.Context, topic string) error
- func (s *Session) Unsubscribe(ctx context.Context) error
- func (s *Session) ValidateMessageHeaders(ctx context.Context, headers map[string]interface{}) error
- func (s *Session) ValidateMessageJSONBody(ctx context.Context, props map[string]interface{}, pos int) error
- func (s *Session) ValidateMessageStandardProperties(ctx context.Context, props amqp.Delivery) error
- func (s *Session) ValidateMessageTextBody(ctx context.Context, expectedMsg string) error
- func (s *Session) WaitForJSONMessageWithProperties(ctx context.Context, timeout time.Duration, props map[string]interface{}) error
- func (s *Session) WaitForMessagesWithStandardProperties(ctx context.Context, timeout time.Duration, count int, props amqp.Delivery) error
- func (s *Session) WaitForTextMessage(ctx context.Context, timeout time.Duration, expectedMsg string) error
- type Steps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey defines a type to store the rabbit session in context.Context.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger logs the HTTP request and response in a configurable file.
func GetLogger ¶
func GetLogger() *Logger
GetLogger returns the logger for rabbit messages in publish/subscribe. If the logger is not created yet, it creates a new instance of Logger.
func NewLogger ¶
NewLogger creates an instance of the logger. It configures the file path where the RabbitMQ interactions are written.
func (Logger) LogPublishedMessage ¶
LogPublishedMessage logs a rabbit message published to a topic.
func (Logger) LogReceivedMessage ¶
LogReceivedMessage logs a rabbit message received from a topic.
func (Logger) LogSubscribedTopic ¶
LogSubscribedTopic logs the subscription to a rabbit topic.
type Session ¶
type Session struct { Connection *amqp.Connection // Messages received from the publish/subscribe channel Messages []amqp.Delivery // Correlator is used to correlate the messages for a specific session Correlator string // contains filtered or unexported fields }
Session contains the information of a rabbit session.
func GetSession ¶
GetSession returns the rabbit session stored in context. Note that the context should be previously initialized with InitializeContext function.
func (*Session) ConfigureConnection ¶
ConfigureConnection creates a rabbit connection based on the URI.
func (*Session) ConfigureHeaders ¶
ConfigureHeaders stores a table of rabbit headers in the application context.
func (*Session) ConfigureStandardProperties ¶
func (s *Session) ConfigureStandardProperties(ctx context.Context, props amqp.Publishing)
ConfigureStandardProperties stores a table of rabbit properties in the application context.
func (*Session) PublishJSONMessage ¶
func (s *Session) PublishJSONMessage(ctx context.Context, topic string, props map[string]interface{}) error
PublishJSONMessage publishes a JSON message in a rabbit topic.
func (*Session) PublishTextMessage ¶
PublishTextMessage publishes a text message in a rabbit topic.
func (*Session) SubscribeTopic ¶
SubscribeTopic subscribes to a rabbit topic to receive messages via a channel.
func (*Session) Unsubscribe ¶
Unsubscribe unsubscribes from rabbit closing the channel associated. If this method is not invoked, then the goroutine created with SubscribeTopic is never closed and will permanently processing messages from the topic until the program is finished.
func (*Session) ValidateMessageHeaders ¶
ValidateMessageHeaders checks if the message rabbit headers are equal the expected values.
func (*Session) ValidateMessageJSONBody ¶
func (s *Session) ValidateMessageJSONBody(ctx context.Context, props map[string]interface{}, pos int) error
ValidateMessageJSONBody checks if the message json body properties of message in position 'pos' are equal the expected values. if pos == -1 then it means last message stored, that is the one stored in s.msg
func (*Session) ValidateMessageStandardProperties ¶
ValidateMessageStandardProperties checks if the message standard rabbit properties are equal the expected values.
func (*Session) ValidateMessageTextBody ¶
ValidateMessageTextBody checks if the message text body is equal to the expected value.
func (*Session) WaitForJSONMessageWithProperties ¶
func (s *Session) WaitForJSONMessageWithProperties(ctx context.Context, timeout time.Duration, props map[string]interface{}) error
WaitForJSONMessageWithProperties waits up to timeout and verifies if there is a message received in the topic with the requested properties.
func (*Session) WaitForMessagesWithStandardProperties ¶
func (s *Session) WaitForMessagesWithStandardProperties(ctx context.Context, timeout time.Duration, count int, props amqp.Delivery) error
WaitForMessagesWithStandardProperties waits for 'count' messages with standard rabbit properties that are equal to the expected values.