Skip to content

Commit

Permalink
Merge pull request #4 from muhammadnawzad/main
Browse files Browse the repository at this point in the history
Indexes columns & adds `content_type` field
  • Loading branch information
broosk1993 authored May 28, 2024
2 parents faa35a5 + 816465e commit 40cbf33
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/generators/outboxable/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
7 changes: 6 additions & 1 deletion lib/outboxable/rabbitmq/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/templates/create_outboxable_outboxes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions lib/templates/mongoid_outbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 40cbf33

Please sign in to comment.