Class: ActionMailerKafka::DeliveryMethod
- Inherits:
-
Object
- Object
- ActionMailerKafka::DeliveryMethod
- Defined in:
- lib/action_mailer_kafka/delivery_method.rb
Constant Summary collapse
- SUPPORTED_MULTIPART_MIME_TYPES =
['multipart/alternative', 'multipart/mixed', 'multipart/related'].freeze
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Instance Method Summary collapse
- #deliver!(mail) ⇒ Object
-
#initialize(**params) ⇒ DeliveryMethod
constructor
settings params allow you to pass in 1.
Constructor Details
#initialize(**params) ⇒ DeliveryMethod
settings params allow you to pass in
-
Your Kafka publisher
With this option, you pass an instance of Kafka Publisher, which inherit from our ActionMailerKafka::BasesProducer or at least support the method ‘publish` with the same parameters. After that, your should be as below: config.action_mailer.eh_mailer_settings =
kafka_mail_topic: 'YourKafkaTopic',
kafka_publisher: PublisherKlass.new
and the data would go through your publisher instance
-
Your kafka client info
With this option, the library will generate a kafka instance for you: config.action_mailer.eh_mailer_settings = {
kafka_mail_topic: 'YourKafkaTopic',
kafka_client_info: {
seed_brokers: ['localhost:9090'],
logger: logger,
ssl_ca_cert: '/path/to/cert'
# For more option on what to pass here, see https://github.com/zendesk/ruby-kafka/blob/master/lib/kafka/client.rb#L20
}
}
Other settings params:
- raise_on_delivery_error
- logger
- fallback
+ fallback_delivery_method
+ fallback_delivery_method_settings
}
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/action_mailer_kafka/delivery_method.rb', line 38 def initialize(**params) @settings = params # Optional config @logger = settings[:logger] @raise_on_delivery_error = settings[:raise_on_delivery_error] # General configuration @service_name = settings[:service_name] || '' @mailer_topic_name = settings.fetch(:kafka_mail_topic) @kafka_publisher = settings[:kafka_publisher] || ActionMailerKafka::BaseProducer.new( logger: @logger, kafka_client_info: settings[:kafka_client_info] ) # Fallback configuration @fallback = settings[:fallback] if @fallback @fallback_delivery_method = Mail::Configuration.instance.lookup_delivery_method( @fallback.fetch(:fallback_delivery_method) ).new( @fallback.fetch(:fallback_delivery_method_settings) ) end rescue KeyError => e raise RequiredParamsError.new(settings, e.) end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
5 6 7 |
# File 'lib/action_mailer_kafka/delivery_method.rb', line 5 def settings @settings end |
Instance Method Details
#deliver!(mail) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/action_mailer_kafka/delivery_method.rb', line 64 def deliver!(mail) mail_data = (mail) @kafka_publisher.publish(mail_data, , @mailer_topic_name) rescue Kafka::Error => e error_msg = "Fail to send email into Kafka due to: #{e.}. Delivered using fallback method" @logger&.error(error_msg) @fallback_delivery_method.deliver!(mail) if @fallback raise KafkaOperationError, error_msg if @raise_on_delivery_error rescue StandardError => e error_msg = "Fail to send email due to: #{e.}" @logger&.error(error_msg) raise ParsingOperationError, error_msg if @raise_on_delivery_error end |