Sha256: a52669f2d5d16b3aeee77a04b8716e9c19c9dce6030e40361e9673e827c487f1

Contents?: true

Size: 1.69 KB

Versions: 6

Compression:

Stored size: 1.69 KB

Contents

module MessageDriver
  module Adapters
    class Base
      include Logging

      attr_reader :broker

      def contexts
        @contexts ||= []
      end

      def initialize(_broker, _configuration)
        fail 'Must be implemented in subclass'
      end

      def new_context
        ctx = build_context
        contexts << ctx
        ctx
      end

      def build_context
        fail 'Must be implemented in subclass'
      end

      def reset_after_tests
        # does nothing, can be overridden by adapters that want to support testing scenarios
      end

      def stop
        if @contexts
          ctxs = @contexts
          @contexts = []
          ctxs.each { |ctx| ctx.invalidate }
        end
      end
    end

    class ContextBase
      include Logging

      attr_reader :adapter
      attr_accessor :valid

      def initialize(adapter)
        @adapter = adapter
        @valid = true
      end

      def publish(_destination, _body, _headers = {}, _properties = {})
        fail 'Must be implemented in subclass'
      end

      def pop_message(_destination, _options = {})
        fail 'Must be implemented in subclass'
      end

      def subscribe(_destination, _options = {}, &_consumer)
        fail "#subscribe is not supported by #{adapter.class}"
      end

      def create_destination(_name, _dest_options = {}, _message_props = {})
        fail 'Must be implemented in subclass'
      end

      def valid?
        @valid
      end

      def invalidate
        @valid = false
      end

      def supports_transactions?
        false
      end

      def supports_client_acks?
        false
      end

      def supports_subscriptions?
        false
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
message-driver-0.6.1 lib/message_driver/adapters/base.rb
message-driver-0.6.0 lib/message_driver/adapters/base.rb
message-driver-0.5.3 lib/message_driver/adapters/base.rb
message-driver-0.5.2 lib/message_driver/adapters/base.rb
message-driver-0.5.1 lib/message_driver/adapters/base.rb
message-driver-0.5.0 lib/message_driver/adapters/base.rb