Class: JetstreamBridge::DlqPublisher

Inherits:
Object
  • Object
show all
Defined in:
lib/jetstream_bridge/consumer/dlq_publisher.rb

Instance Method Summary collapse

Constructor Details

#initialize(jts) ⇒ DlqPublisher



9
10
11
# File 'lib/jetstream_bridge/consumer/dlq_publisher.rb', line 9

def initialize(jts)
  @jts = jts
end

Instance Method Details

#publish(msg, ctx, reason:, error_class:, error_message:) ⇒ Boolean

Sends original payload to DLQ with explanatory headers/context



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jetstream_bridge/consumer/dlq_publisher.rb', line 15

def publish(msg, ctx, reason:, error_class:, error_message:)
  return true unless JetstreamBridge.config.use_dlq

  envelope = build_envelope(ctx, reason, error_class, error_message)
  headers  = build_headers(msg.header, reason, ctx.deliveries, envelope)
  @jts.publish(JetstreamBridge.config.dlq_subject, msg.data, header: headers)
  true
rescue StandardError => e
  Logging.error(
    "DLQ publish failed event_id=#{ctx.event_id}: #{e.class} #{e.message}",
    tag: 'JetstreamBridge::Consumer'
  )
  false
end