Skip to content

Commit ae745d9

Browse files
committed
Add --log-out-of-order-messages flag
1 parent 072344b commit ae745d9

File tree

6 files changed

+7
-3
lines changed

6 files changed

+7
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ messages published with perf-test can be consumed by `omq` or vice versa, and th
8888
--consumer-uri string URI for consuming
8989
-y, --consumers int The number of consumers to start (default 1)
9090
-h, --help help for omq
91+
--log-out-of-order-messages Print a log line when a message is received that is older than the previously received message
9192
-d, --message-durability Mark messages as durable (default true)
9293
--message-priority string Message priority (0-255, default=unset)
9394
--metric-tags strings Prometheus label-value pairs, eg. l1=v1,l2=v2

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ func RootCmd() *cobra.Command {
213213
rootCmd.PersistentFlags().IntVar(&cfg.ConsumerCredits, "consumer-credits", 1, "AMQP-1.0 consumer credits / STOMP prefetch count")
214214
rootCmd.PersistentFlags().DurationVarP(&cfg.ConsumerLatency, "consumer-latency", "L", 0*time.Second, "consumer latency (time to accept message)")
215215
rootCmd.PersistentFlags().StringSliceVar(&metricTags, "metric-tags", []string{}, "Prometheus label-value pairs, eg. l1=v1,l2=v2")
216+
rootCmd.PersistentFlags().
217+
BoolVar(&cfg.LogOutOfOrder, "log-out-of-order-messages", false, "Print a log line when a message is received that is older than the previously received message")
216218

217219
rootCmd.AddCommand(amqp_amqp)
218220
rootCmd.AddCommand(amqp_stomp)

pkg/amqp10_client/consumer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (c Amqp10Consumer) Start(ctx context.Context, subscribed chan bool) {
9999
timeSent, latency := utils.CalculateEndToEndLatency(&payload)
100100
m.With(prometheus.Labels{"protocol": "amqp-1.0"}).Observe(latency.Seconds())
101101

102-
if timeSent.Before(previousMessageTimeSent) {
102+
if c.Config.LogOutOfOrder && timeSent.Before(previousMessageTimeSent) {
103103
metrics.MessagesConsumedOutOfOrder.With(prometheus.Labels{"protocol": "amqp-1.0", "priority": priority}).Inc()
104104
log.Info("Out of order message received. This message was sent before the previous message", "this messsage", timeSent, "previous message", previousMessageTimeSent)
105105
}

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type Config struct {
5555
MqttPublisher MqttOptions
5656
MqttConsumer MqttOptions
5757
MetricTags map[string]string
58+
LogOutOfOrder bool
5859
}
5960

6061
func NewConfig() Config {

pkg/mqtt_client/consumer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (c MqttConsumer) Start(ctx context.Context, subscribed chan bool) {
7070
timeSent, latency := utils.CalculateEndToEndLatency(&payload)
7171
m.Observe(latency.Seconds())
7272

73-
if timeSent.Before(previousMessageTimeSent) {
73+
if c.Config.LogOutOfOrder && timeSent.Before(previousMessageTimeSent) {
7474
metrics.MessagesConsumedOutOfOrder.With(prometheus.Labels{"protocol": "mqtt"}).Inc()
7575
log.Info("Out of order message received. This message was sent before the previous message", "this messsage", timeSent, "previous message", previousMessageTimeSent)
7676
}

pkg/stomp_client/consumer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (c StompConsumer) Start(ctx context.Context, subscribed chan bool) {
8080

8181
priority := msg.Header.Get("priority")
8282

83-
if timeSent.Before(previousMessageTimeSent) {
83+
if c.Config.LogOutOfOrder && timeSent.Before(previousMessageTimeSent) {
8484
metrics.MessagesConsumedOutOfOrder.With(prometheus.Labels{"protocol": "amqp-1.0", "priority": priority}).Inc()
8585
log.Info("Out of order message received. This message was sent before the previous message", "this messsage", timeSent, "previous message", previousMessageTimeSent)
8686
}

0 commit comments

Comments
 (0)