Class: Stapfen::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/stapfen/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Message

Returns a new instance of Message.



5
6
7
8
9
10
11
# File 'lib/stapfen/message.rb', line 5

def initialize(opts={})
  super()
  @body        = opts[:body]
  @destination = opts[:destination]
  @message_id  = opts[:message_id]
  @original    = opts[:original]
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/stapfen/message.rb', line 3

def body
  @body
end

#destinationObject (readonly)

Returns the value of attribute destination.



3
4
5
# File 'lib/stapfen/message.rb', line 3

def destination
  @destination
end

#message_idObject (readonly)

Returns the value of attribute message_id.



3
4
5
# File 'lib/stapfen/message.rb', line 3

def message_id
  @message_id
end

#originalObject (readonly)

Returns the value of attribute original.



3
4
5
# File 'lib/stapfen/message.rb', line 3

def original
  @original
end

Class Method Details

.from_jms(message) ⇒ Stapfen::Message

Create an instance of Stapfen::Message from the passed in ActiveMQBytesMessage which a JMS consumer should receive

Parameters:

  • message (ActiveMQBytesMessage)

Returns:



34
35
36
37
38
39
40
41
42
43
# File 'lib/stapfen/message.rb', line 34

def self.from_jms(message)
  unless message.kind_of? Java::JavaxJms::Message
    raise Stapfen::InvalidMessageError, message.inspect
  end

  return self.new(:body => message.data,
                  :destination => message.jms_destination.getQualifiedName,
                  :message_id => message.jms_message_id,
                  :original => message)
end

.from_kafka(message) ⇒ Stapfen::Message

Create an instance of Stapfen::Message from the passed in String which a Kafka consumer should receive

Parameters:

  • message (String)

Returns:



50
51
52
53
54
55
56
# File 'lib/stapfen/message.rb', line 50

def self.from_kafka(message)
  unless message.kind_of? String
    raise Stapfen::InvalidMessageError, message.inspect
  end

  return self.new(:body => message)
end

.from_stomp(message) ⇒ Stapfen::Message

Create an instance of Stapfen::Message from the passed in Stomp::Message

Parameters:

  • message (Stomp::Message)

    A message created by the Stomp gem

Returns:



18
19
20
21
22
23
24
25
26
27
# File 'lib/stapfen/message.rb', line 18

def self.from_stomp(message)
  unless message.kind_of? Stomp::Message
    raise Stapfen::InvalidMessageError, message.inspect
  end

  return self.new(:body => message.body,
                  :destination => message.headers['destination'],
                  :message_id => message.headers['message-id'],
                  :original => message)
end