Skip to content

Commit

Permalink
Add support of debugging info in RabbitMQWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanecek committed Aug 12, 2024
1 parent d8d1ea4 commit e9eca3c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
20 changes: 19 additions & 1 deletion source/Ansible-RabbitMQ-Tests/RabbitMQClientTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ RabbitMQClientTest >> assertQueueStatusAfterConsuming: messagesToSend from: queu
configuredBy: [ :options |
options
at: #queueName put: queueName;
at: #queueDurable put: false
at: #queueDurable put: false;
at: #enableDebuggingLogs put: true
]
processingMessagesWith: [ :messageReceived |
messageWasConsumed := true.
Expand Down Expand Up @@ -267,6 +268,23 @@ RabbitMQClientTest >> testDebuggingLogsEnabled [
'\[INFO\] AMQP connection localhost\:(\d+)->localhost\:5672 closed due to Normal shutdown' }
]

{ #category : 'tests' }
RabbitMQClientTest >> testDebuggingLogsEnabledInWorker [

| queueName messagesToSend |
queueName := self queueName.
messagesToSend := 'Do it!'.

self assertQueueStatusAfterPublishing: messagesToSend on: queueName.

self
runMemoryLoggerDuring: [ self assertQueueStatusAfterConsuming: messagesToSend from: queueName ]
assertingLogRecordsMatchRegexes:
{ '\[INFO\] AMQP connection localhost\:(\d+)->localhost\:5672 established successfully' .
'\[DEBUG\] RabbitMQ message consumed \{"messageConsumed"\:"Do it!","routingKey"\:"tasks-for-testDebuggingLogsEnabledInWorker","connectionDescription"\:"localhost\:(\d+)->localhost\:5672"\}' .
'\[INFO\] AMQP connection localhost\:(\d+)->localhost\:5672 closed due to Normal shutdown' }
]

{ #category : 'tests' }
RabbitMQClientTest >> testDebuggingLogsTurnedOff [

Expand Down
24 changes: 14 additions & 10 deletions source/Ansible-RabbitMQ/RabbitMQPublisher.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ RabbitMQPublisher >> initializeConfiguredBy: anOptionsDictionary [
channelConfigurationCommands := OrderedCollection new
]

{ #category : 'private - logging' }
RabbitMQPublisher >> logDebuggingInfoFor: aMessage publishedTo: aQueueName [

self shouldLogDebuggingInfo then: [
LogRecord emitStructuredDebuggingInfo: 'RabbitMQ message published' with: [ :data |
data
at: #messagePublished put: aMessage;
at: #routingKey put: aQueueName;
at: #connectionDescription put: connection connectionPairsDescription
]
]
]

{ #category : 'configuring' }
RabbitMQPublisher >> onPublicationConfirmationDo: anAckBlock onRejectionDo: aNackBlock [

Expand All @@ -64,7 +77,6 @@ RabbitMQPublisher >> publish: aMessageCollection onQueueNamed: aQueueName [
RabbitMQPublisher >> publishOnly: aMessage onQueueNamed: aQueueName [

| tryToPublishMessage |

self ensureChannelOpen.
tryToPublishMessage := [
channel
Expand All @@ -73,15 +85,7 @@ RabbitMQPublisher >> publishOnly: aMessage onQueueNamed: aQueueName [
routingKey: aQueueName
properties: self persistentDeliveryMode
].

self shouldLogDebuggingInfo then: [
LogRecord emitStructuredDebuggingInfo: 'RabbitMQ message published' with: [ :data |
data
at: #messagePublished put: aMessage;
at: #routingKey put: aQueueName;
at: #connectionDescription put: connection connectionPairsDescription
]
].
self logDebuggingInfoFor: aMessage publishedTo: aQueueName.

tryToPublishMessage
on: self connectivityErrors
Expand Down
16 changes: 15 additions & 1 deletion source/Ansible-RabbitMQ/RabbitMQWorker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,20 @@ RabbitMQWorker >> initializeConfiguredBy: anOptionsDictionary processingMessages
messageProcessor := aMessageProcessor
]

{ #category : 'private' }
{ #category : 'private - logging' }
RabbitMQWorker >> logDebuggingInfoFor: aMessage [

self shouldLogDebuggingInfo then: [
LogRecord emitStructuredDebuggingInfo: 'RabbitMQ message consumed' with: [ :data |
data
at: #messageConsumed put: aMessage body utf8Decoded;
at: #routingKey put: self queueName;
at: #connectionDescription put: connection connectionPairsDescription
]
]
]

{ #category : 'private - logging' }
RabbitMQWorker >> logDisconnectionDueTo: anError [

LogRecord emitError:
Expand All @@ -89,6 +102,7 @@ RabbitMQWorker >> startConsumingFromQueue [

channel prefetchCount: 1.
channel consumeFrom: self queueName applying: [ :message |
self logDebuggingInfoFor: message.
messageProcessor value: message.
channel basicAck: message method deliveryTag
]
Expand Down

0 comments on commit e9eca3c

Please sign in to comment.