Module: RServiceBus2

Defined in:
lib/rservicebus2.rb,
lib/rservicebus2/mq.rb,
lib/rservicebus2/host.rb,
lib/rservicebus2/agent.rb,
lib/rservicebus2/audit.rb,
lib/rservicebus2/stats.rb,
lib/rservicebus2/config.rb,
lib/rservicebus2/message.rb,
lib/rservicebus2/monitor.rb,
lib/rservicebus2/test/bus.rb,
lib/rservicebus2/saga/base.rb,
lib/rservicebus2/saga/data.rb,
lib/rservicebus2/appresource.rb,
lib/rservicebus2/monitor/dir.rb,
lib/rservicebus2/saga_loader.rb,
lib/rservicebus2/transporter.rb,
lib/rservicebus2/cron_manager.rb,
lib/rservicebus2/errormessage.rb,
lib/rservicebus2/mq/beanstalk.rb,
lib/rservicebus2/saga/manager.rb,
lib/rservicebus2/saga_storage.rb,
lib/rservicebus2/state_manager.rb,
lib/rservicebus2/state_storage.rb,
lib/rservicebus2/circuitbreaker.rb,
lib/rservicebus2/handler_loader.rb,
lib/rservicebus2/monitor/xmldir.rb,
lib/rservicebus2/sendat_manager.rb,
lib/rservicebus2/sendat_storage.rb,
lib/rservicebus2/appresource/dir.rb,
lib/rservicebus2/endpointmapping.rb,
lib/rservicebus2/handler_manager.rb,
lib/rservicebus2/monitor/message.rb,
lib/rservicebus2/appresource/file.rb,
lib/rservicebus2/helper_functions.rb,
lib/rservicebus2/resource_manager.rb,
lib/rservicebus2/saga_storage/dir.rb,
lib/rservicebus2/monitor_configure.rb,
lib/rservicebus2/state_storage/dir.rb,
lib/rservicebus2/statistic_manager.rb,
lib/rservicebus2/appresource/fluiddb.rb,
lib/rservicebus2/monitor/dirnotifier.rb,
lib/rservicebus2/sendat_storage/file.rb,
lib/rservicebus2/appresource/fluiddb2.rb,
lib/rservicebus2/message/subscription.rb,
lib/rservicebus2/subscription_manager.rb,
lib/rservicebus2/subscription_storage.rb,
lib/rservicebus2/appresource_configure.rb,
lib/rservicebus2/message/verboseoutput.rb,
lib/rservicebus2/saga_storage/inmemory.rb,
lib/rservicebus2/state_storage/inmemory.rb,
lib/rservicebus2/message/statisticoutput.rb,
lib/rservicebus2/sendat_storage/inmemory.rb,
lib/rservicebus2/usermessage/withpayload.rb,
lib/rservicebus2/subscription_storage/file.rb,
lib/rservicebus2/subscription_storage_configure.rb

Overview

Initial definition of the namespace

Defined Under Namespace

Classes: Agent, AppResource, AppResourceDir, AppResourceFile, AppResourceFluidDb, AppResourceFluidDb2, Audit, CircuitBreaker, ClassNotFoundForMsg, Config, ConfigFromEnv, ConfigFromSetter, ConfigureAppResource, ConfigureMonitor, ConfigureSubscriptionStorage, CouldNotConnectToDestination, CronManager, EndpointMapping, ErrorMessage, Globber, HandlerLoader, HandlerManager, Host, JobTooBigError, MQ, MQBeanstalk, Message, MessageArrivedWhileCricuitBroken, MessageStatisticOutputOff, MessageStatisticOutputOn, MessageSubscription, MessageVerboseOutputOff, MessageVerboseOutputOn, Monitor, MonitorDir, MonitorDirNotifier, MonitorMessage, MonitorXmlDir, NoHandlerFound, NoMatchingMsgForCron, NoMsgToProcess, PropertyNotSet, QueueNotFoundForMsg, ResourceManager, SagaBase, SagaData, SagaLoader, SagaManager, SagaStorage, SagaStorageDir, SagaStorageInMemory, SendAtManager, SendAtStorage, SendAtStorageFile, SendAtStorageInMemory, StateManager, StateStorage, StateStorageDir, StateStorageInMemory, StatisticManager, Stats, SubscriptionManager, SubscriptionStorage, SubscriptionStorageFile, TestBus, Transporter, UserMessageWithPayload

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check_environment_variable(string) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/rservicebus2/helper_functions.rb', line 77

def self.check_environment_variable(string)
  return false if ENV[string].nil?
  return true if ENV[string] == true || ENV[string] =~ (/(true|t|yes|y|1)$/i)
  return false if ENV[string] == false ||
                  ENV[string].nil? ||
                  ENV[string] =~ (/(false|f|no|n|0)$/i)
  fail ArgumentError, "invalid value for Environment Variable: \"#{string}\""
end

.check_for_reply(queue_name) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/rservicebus2/helper_functions.rb', line 63

def self.check_for_reply(queue_name)
  ENV['RSBMQ'] = 'beanstalk://localhost' if ENV['RSBMQ'].nil?
  agent = RServiceBus2::Agent.new
  msg = agent.check_for_reply(queue_name)
  Audit.new(agent).audit_incoming(msg)

  msg
end

.convert_dto_to_hash(obj) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/rservicebus2/helper_functions.rb', line 2

def self.convert_dto_to_hash(obj)
  hash = {}
  obj.instance_variables.each do |var|
    hash[var.to_s.delete('@')] = obj.instance_variable_get(var)
  end
  hash
end

.convert_dto_to_json(obj) ⇒ Object



10
11
12
# File 'lib/rservicebus2/helper_functions.rb', line 10

def self.convert_dto_to_json(obj)
  convert_dto_to_hash(obj).to_json
end

.create_anonymous_class(name_for_class) ⇒ Object



31
32
33
34
35
# File 'lib/rservicebus2/helper_functions.rb', line 31

def self.create_anonymous_class(name_for_class)
  new_anonymous_class = Class.new(Object)
  Object.const_set(name_for_class, new_anonymous_class)
  Object.const_get(name_for_class).new
end

.get_value(name, default = nil) ⇒ Object



37
38
39
40
41
# File 'lib/rservicebus2/helper_functions.rb', line 37

def self.get_value(name, default = nil)
  value = (ENV[name].nil? || ENV[name] == '') ? default : ENV[name]
  log "Env value: #{name}: #{value}"
  value
end

.log(string, ver = false) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/rservicebus2/helper_functions.rb', line 14

def self.log(string, ver = false)
  return if check_environment_variable('TESTING')

  type = ver ? 'VERB' : 'INFO'
  if check_environment_variable('VERBOSE') || !ver
    timestamp = Time.new.strftime('%Y-%m-%d %H:%M:%S')
    puts "[#{type}] #{timestamp} :: #{string}"
  end
end

.rlog(string) ⇒ Object



24
25
26
27
28
29
# File 'lib/rservicebus2/helper_functions.rb', line 24

def self.rlog(string)
  return unless check_environment_variable('RSBVERBOSE')

  timestamp = Time.new.strftime('%Y-%m-%d %H:%M:%S')
  puts "[RSB] #{timestamp} :: #{string}"
end

.send_msg(msg, response_queue = 'agent') ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rservicebus2/helper_functions.rb', line 43

def self.send_msg(msg, response_queue = 'agent')
  require 'rservicebus2/endpointmapping'
  endpoint_mapping = EndpointMapping.new
  endpoint_mapping.configure
  queue_name = endpoint_mapping.get(msg.class.name)

  ENV['RSBMQ'] = 'beanstalk://localhost' if ENV['RSBMQ'].nil?
  agent = RServiceBus2::Agent.new
  Audit.new(agent).audit_to_queue(msg)
  agent.send_msg(msg, queue_name, response_queue)

rescue QueueNotFoundForMsg => e
  msg = "\n"
  msg = "#{msg}*** Queue not found for, #{e.message}\n"
  msg = "#{msg}*** Ensure you have an environment variable set for this
          Message Type, eg, \n"
  msg = "#{msg}*** MESSAGE_ENDPOINT_MAPPINGS=#{e.message}:<QueueName>\n"
  raise StandardError, msg
end

.tick(string) ⇒ Object



72
73
74
75
# File 'lib/rservicebus2/helper_functions.rb', line 72

def self.tick(string)
  puts "[TICK] #{Time.new.strftime('%Y-%m-%d %H:%M:%S.%6N')} ::
    #{caller[0]}. #{string}"
end

Instance Method Details

#get_for_reportingObject



61
62
63
64
65
66
67
# File 'lib/rservicebus2/stats.rb', line 61

def get_for_reporting
  "T:#{@total_processed};
   E:#{@total_errored};
   S:#{@total_sent};
   P:#{@total_published};
   R:#{@total_reply}"
end

#get_for_reporting_2Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rservicebus2/stats.rb', line 49

def get_for_reporting_2
  return unless @written == false

  @written = true
  types = Hash.new(0)
  ObjectSpace.each_object do |obj|
    types[obj.class] += 1
  end

  types
end