Sha256: 0494740d2fe6e7cb6395ca72c40f0ef51f43ad52053af806eae76a740fe7a4b4

Contents?: true

Size: 1.54 KB

Versions: 16

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  module Rabbit
    # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>

    # @!attribute [r] correlation
    #   @return [String] Is a string uniq generated by SecureRandom
    #
    # Manage properties to message sending in rabbitmq queue
    class Propertie
      attr_reader :correlation

      # Initialize a message sending to rabbitmq
      def initialize(instance = 1)
        Tools::Log.instance.debug 'initalize a propertie to message'
        @correlation = SecureRandom.uuid
        @instance = instance
      rescue
        raise Errors::Rabbit::Propertie::Initialize
      end

      # Define options sending to rabbitmq
      def options
        base.merge(routing_key: Tools::Cluster.instance.queue_to(@instance))
      rescue
        raise Errors::Rabbit::Propertie::Options
      end

      # Define option sending to rabbitmq for janus admin message
      def options_admin(_type_request)
        base.merge(routing_key: routing_key_admin)
      rescue
        raise Errors::Rabbit::Propertie::Options_admin
      end

      private

      def determine_routing_key(type_request)
        cluster = Tools::Cluster.instance

        if type_request.include?('admin')
          cluster.queue_admin_to(@instance)
        else
          cluster.queue_to(@instance)
        end
      end

      def base
        { correlation_id: @correlation, content_type: 'application/json' }
      end

      def routing_key_admin
        Tools::Cluster.instance.queue_admin_to(@instance)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.6.0.pre.247 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.246 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.244 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.240 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.239 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.238 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.233 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.229 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.228 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.227 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.6.0.pre.226 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.5.1.pre.217 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.5.1 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.5.1.pre.215 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.5.0 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.5.0.pre.213 lib/rrj/rabbit/propertie.rb