Sha256: bf49cc26ffc6dc663d47724476f7d2fb9af0ab207f19d8a5769ed9902da39f3b

Contents?: true

Size: 1.54 KB

Versions: 20

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
        {
          routing_key: Tools::Cluster.instance.queue_to(@instance),
          correlation_id: @correlation,
          content_type: 'application/json'
        }
      rescue
        raise Errors::Rabbit::Propertie::Options
      end

      # Define option sending to rabbitmq for janus admin message
      def options_admin(type_request)
        {
          routing_key: determine_routing_key(type_request),
          correlation_id: @correlation,
          content_type: 'application/json'
        }
      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
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.2.0.pre.170 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.2.0.pre.168 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.2.0.pre.167 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.2.0.pre.166 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.2.0.pre.165 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.2.0.pre.164 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.2.0.pre.161 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.2.0.pre.159 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.2.0.pre.42 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.1 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.1.pre.139 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.0 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.0.pre.137 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.0.pre.136 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.0.pre.135 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.0.pre.132 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.0.pre.131 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.0.pre.130 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.0.pre.129 lib/rrj/rabbit/propertie.rb
ruby_rabbitmq_janus-2.1.0.pre.128 lib/rrj/rabbit/propertie.rb