Module: StompingGround::Stomp

Defined in:
lib/stomping_ground/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#message_body=(value) ⇒ Object (writeonly)

Sets the attribute message_body

Parameters:

  • value

    the value to set the attribute message_body to.



9
10
11
# File 'lib/stomping_ground/server.rb', line 9

def message_body=(value)
  @message_body = value
end

#queue_name=(value) ⇒ Object (writeonly)

Sets the attribute queue_name

Parameters:

  • value

    the value to set the attribute queue_name to.



10
11
12
# File 'lib/stomping_ground/server.rb', line 10

def queue_name=(value)
  @queue_name = value
end

#sent_message_dir=(value) ⇒ Object (writeonly)

Sets the attribute sent_message_dir

Parameters:

  • value

    the value to set the attribute sent_message_dir to.



11
12
13
# File 'lib/stomping_ground/server.rb', line 11

def sent_message_dir=(value)
  @sent_message_dir = value
end

Instance Method Details

#post_initObject



13
# File 'lib/stomping_ground/server.rb', line 13

def post_init; end

#receive_data(data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/stomping_ground/server.rb', line 16

def receive_data data
  append_data(data)

  each_frame do |frame|
    frame_info = parse(frame)
    case frame_info[:command]
    when "CONNECT"
      send_data "CONNECTED\n"
      send_data "version:1.1\n"
      send_data "heart-beat:0,0\n" if frame_info[:'heart-beat']
      send_data "\n"
      send_data "\0"
    when "SUBSCRIBE"
      if @queue_name.nil? || frame_info[:destination] == @queue_name
        message = @message_body || "hello"
        send_data "MESSAGE\n"
        send_data "subscription:#{frame_info[:id]}\n"
        send_data "message-id:007\n"
        send_data "destination:#{frame_info[:destination]}\n"
        send_data "content-type:text/plain\n"
        send_data "content-length:#{message.length}\n"
        send_data "\n"
        send_data "#{message}\0"
      end
    when "DISCONNECT"
      if frame_info[:'receipt-id']
        send_data "RECEIPT\n"
        send_data "receipt-id:#{frame_info[:'receipt-id']}\n"
        send_data "\0"
      end
      close_connection
    when "SEND"
      filename = sent_message_filename_for(frame)
      if filename
        dirname = File.dirname(filename)
        FileUtils.mkdir_p(dirname) if !File.exists?(dirname)
        File.open(filename, "w") { |file| file.write(frame) }
      end
    end
  end
end

#unbindObject



14
# File 'lib/stomping_ground/server.rb', line 14

def unbind;    end