Class: JSparrow::Interactors::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/interaction/client.rb

Overview

Client to send and receive messages to/from the JMS provider.

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/interaction/client.rb', line 10

def initialize(connection)
  @connection = connection

  @connection_factories = {}
  @queues               = {}
  @queue_senders        = {}
  @queue_receivers      = {}
  @topics               = {}
  @topic_senders        = {}
  @topic_receivers      = {}
end

Instance Method Details

#is_started?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/interaction/client.rb', line 22

def is_started?
  @connection.is_opened?
end

#is_stoped?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/interaction/client.rb', line 32

def is_stoped?
  @connection.is_closed?
end

#queue(queue_name) ⇒ Object

Raises:

  • (NameError)


44
45
46
47
48
# File 'lib/interaction/client.rb', line 44

def queue(queue_name)
  raise NameError, "Queue '#{queue_name}' does not exist." unless queue_enabled?(queue_name)

  @queues[queue_name]
end

#queue_enabled?(queue_name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/interaction/client.rb', line 40

def queue_enabled?(queue_name)
  @connection.configuration.enabled_queues.include?(queue_name)
end

#queue_receiver(queue_name) ⇒ Object



55
56
57
58
# File 'lib/interaction/client.rb', line 55

def queue_receiver(queue_name)
  @queue_receivers[queue_name] ||=
      Messaging::Receiver.new(queue_connection_factory, queue(queue_name))
end

#queue_sender(queue_name) ⇒ Object



50
51
52
53
# File 'lib/interaction/client.rb', line 50

def queue_sender(queue_name)
  @queue_senders[queue_name] ||=
      Messaging::Sender.new(queue_connection_factory, queue(queue_name))
end

#startObject



26
27
28
29
30
# File 'lib/interaction/client.rb', line 26

def start
  @connection.open

  @connection_factories, @queues, @topics = lookup_resources
end

#stopObject



36
37
38
# File 'lib/interaction/client.rb', line 36

def stop
  @connection.close
end

#topic(topic_name) ⇒ Object

Raises:

  • (NameError)


64
65
66
67
68
# File 'lib/interaction/client.rb', line 64

def topic(topic_name)
  raise NameError, "Topic '#{topic_name}' does not exist." unless topic_enabled?(topic_name)

  @topics[topic_name]
end

#topic_enabled?(topic_name) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/interaction/client.rb', line 60

def topic_enabled?(topic_name)
  @connection.configuration.enabled_topics.include?(topic_name)
end

#topic_receiver(topic_name) ⇒ Object



75
76
77
78
# File 'lib/interaction/client.rb', line 75

def topic_receiver(topic_name)
  @topic_receivers[topic_name] ||=
      Messaging::Receiver.new(topic_connection_factory, topic(topic_name))
end

#topic_sender(topic_name) ⇒ Object



70
71
72
73
# File 'lib/interaction/client.rb', line 70

def topic_sender(topic_name)
  @topic_senders[topic_name] ||=
      Messaging::Sender.new(topic_connection_factory, topic(topic_name))
end