Sha256: 81f41a243deff0f3bbe52bf671b0de588ac9f1faf685208f8e571ecf08ed426d

Contents?: true

Size: 832 Bytes

Versions: 3

Compression:

Stored size: 832 Bytes

Contents

# frozen_string_literal: true

require_relative '../dapr'
require 'semantic_logger'
require 'dapr-client'
require 'dapr/proto/runtime/v1/dapr_services_pb'

module Rubyists
  module Dapr
    # The namespace for the Dapr client
    module Client
      include SemanticLogger::Loggable
      DAPR_PORT = ENV.fetch('DAPR_GRPC_PORT', '5001')
      DAPR_URI = ENV.fetch('DAPR_GRPC_HOST', 'localhost')
      DAPR_STUB = ::Dapr::Proto::Runtime::V1::Dapr::Stub

      def self.client
        logger.info "Creating Dapr client for #{DAPR_URI}:#{DAPR_PORT}"
        DAPR_STUB.new("#{DAPR_URI}:#{DAPR_PORT}", :this_channel_is_insecure)
      end

      def self.singleton
        @singleton ||= client
      end

      def client
        self.class.client
      end

      def singleton
        self.class.singleton
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dapr-0.1.4 lib/dapr/client.rb
dapr-0.1.3 lib/dapr/client.rb
dapr-0.1.2 lib/dapr/client.rb