mirror of
https://github.com/ditkrg/outboxable.git
synced 2026-01-22 22:06:47 +00:00
Adds initializer template
This commit is contained in:
parent
5079299aa1
commit
cbed0bfece
36
lib/templates/initializer.rb
Normal file
36
lib/templates/initializer.rb
Normal file
@ -0,0 +1,36 @@
|
||||
# This monkey patch allows you to customize the message format that you publish to your broker.
|
||||
# By default, Outboxable publishes a CloudEvent message to your broker.
|
||||
module Outboxable
|
||||
module RabbitMq
|
||||
class Publisher
|
||||
# Override this method to customize the message format that you publish to your broker
|
||||
# DO NOT CHANGE THE METHOD SIGNATURE
|
||||
def to_envelope(resource:)
|
||||
{
|
||||
id: resource.id,
|
||||
source: 'http://localhost:3000',
|
||||
specversion: '1.0',
|
||||
type: resource.routing_key,
|
||||
datacontenttype: 'application/json',
|
||||
data: @resource.payload
|
||||
}.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Outboxable.configure do |config|
|
||||
# Specify the ORM you are using. For now, only ActiveRecord is supported.
|
||||
config.orm = :activerecord
|
||||
|
||||
# Specify the message broker you are using. For now, only RabbitMQ is supported.
|
||||
config.message_broker = :rabbitmq
|
||||
|
||||
# RabbitMQ configurations
|
||||
config.rabbitmq_host = ENV.fetch('RABBITMQ__HOST')
|
||||
config.rabbitmq_port = ENV.fetch('RABBITMQ__PORT', 5672)
|
||||
config.rabbitmq_user = ENV.fetch('RABBITMQ__USER')
|
||||
config.rabbitmq_password = ENV.fetch('RABBITMQ__PASSWORD')
|
||||
config.rabbitmq_vhost = ENV.fetch('RABBITMQ__VHOST')
|
||||
config.rabbitmq_event_bus_exchange = ENV.fetch('EVENTBUS__EXCHANGE_NAME')
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user