diff --git a/lib/generators/outboxable/install_generator.rb b/lib/generators/outboxable/install_generator.rb index caa3062..d1a7c09 100644 --- a/lib/generators/outboxable/install_generator.rb +++ b/lib/generators/outboxable/install_generator.rb @@ -5,8 +5,8 @@ class InstallGenerator < Rails::Generators::Base source_root File.expand_path('../../templates', __dir__) class_option :orm, type: :string, default: 'activerecord' - def initialize - super + def initialize(*args) + super(*args) @orm = options[:orm] || 'activerecord' %w[activerecord mongoid].include?(@orm) || raise(ArgumentError, 'Invalid ORM. Only ActiveRecord and Mongoid are supported.') diff --git a/lib/outboxable/rabbitmq/publisher.rb b/lib/outboxable/rabbitmq/publisher.rb index 034d1e5..1770881 100644 --- a/lib/outboxable/rabbitmq/publisher.rb +++ b/lib/outboxable/rabbitmq/publisher.rb @@ -20,7 +20,12 @@ def publish exchange = channel.topic(@resource.exchange, durable: true) # 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: @resource.try(:content_type) || 'application/json' + ) # Wait for confirmation confirmed = channel.wait_for_confirms diff --git a/lib/templates/create_outboxable_outboxes.rb b/lib/templates/create_outboxable_outboxes.rb index 800acdb..02a6e7b 100644 --- a/lib/templates/create_outboxable_outboxes.rb +++ b/lib/templates/create_outboxable_outboxes.rb @@ -7,6 +7,7 @@ def change 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 @@ -21,5 +22,7 @@ def change t.timestamps end + + add_index :outboxes, %i[status last_attempted_at], name: 'index_outboxes_on_outboxable_status_and_last_attempted_at' end end diff --git a/lib/templates/mongoid_outbox.rb b/lib/templates/mongoid_outbox.rb index f905c51..cbe3dd7 100644 --- a/lib/templates/mongoid_outbox.rb +++ b/lib/templates/mongoid_outbox.rb @@ -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