Adds content_type configuration

This commit is contained in:
Muhammad Nawzad 2024-05-28 13:44:54 +03:00
parent e5ebfb84d0
commit 035a9822ee
No known key found for this signature in database
GPG Key ID: B954B6AAE33940B2
3 changed files with 14 additions and 1 deletions

View File

@ -19,8 +19,19 @@ module Outboxable
# Declare a exchange
exchange = channel.topic(@resource.exchange, durable: true)
content_type = if @resource.respond_to?(:content_type) && @resource.content_type.present?
@resource.content_type
else
'application/json'
end
# Publish the CloudEvent resource to the exchange
exchange.publish(to_envelope(resource: @resource), routing_key: @resource.routing_key, headers: @resource.try(:headers) || {})
exchange.publish(
to_envelope(resource: @resource),
routing_key: @resource.routing_key,
headers: @resource.try(:headers) || {},
content_type:
)
# Wait for confirmation
confirmed = channel.wait_for_confirms

View File

@ -7,6 +7,7 @@ class CreateOutboxableOutboxes < ActiveRecord::Migration[7.0]
t.string :exchange, null: false, default: ''
t.string :routing_key, null: false, default: ''
t.string :content_type, null: false, default: 'application/json'
t.integer :attempts, null: false, default: 0
t.datetime :last_attempted_at, null: true

View File

@ -10,6 +10,7 @@ class Outbox
field :exchange, type: String, default: ''
field :routing_key, type: String, default: ''
field :content_type, type: String, default: 'application/json'
field :attempts, type: Integer, default: 0