Module: EventMachine::Protocols::Stomp

Includes:
LineText2
Defined in:
lib/protocols/stomp.rb

Overview

Defined Under Namespace

Classes: Message

Constant Summary

Constants included from LineText2

LineText2::MaxBinaryLength, LineText2::MaxLineLength

Instance Method Summary collapse

Methods included from LineText2

#receive_data, #set_delimiter, #set_line_mode, #set_text_mode, #unbind

Instance Method Details

#connect(parms = {}) ⇒ Object

STOMP verbs



114
115
116
# File 'lib/protocols/stomp.rb', line 114

def connect parms={}
	send_frame "CONNECT", parms
end

#init_message_readerObject



105
106
107
108
109
110
# File 'lib/protocols/stomp.rb', line 105

def init_message_reader
	@stomp_initialized = true
	set_delimiter "\n"
	set_line_mode
	@stomp_message = Message.new
end

#receive_binary_data(data) ⇒ Object



99
100
101
102
103
# File 'lib/protocols/stomp.rb', line 99

def receive_binary_data data
	@stomp_message.body = data[0..-2]
	receive_msg(@stomp_message) if respond_to?(:receive_msg)
	init_message_reader
end

#receive_line(line) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/protocols/stomp.rb', line 86

def receive_line line
	@stomp_initialized || init_message_reader
	@stomp_message.consume_line(line) {|outcome|
		if outcome.first == :sized_text
			set_text_mode outcome[1]
		elsif outcome.first == :unsized_text
			set_delimiter "\0"
		elsif outcome.first == :dispatch
			receive_msg(@stomp_message) if respond_to?(:receive_msg)
			init_message_reader
		end
	}
end

#send(destination, body, parms = {}) ⇒ Object



117
118
119
# File 'lib/protocols/stomp.rb', line 117

def send destination, body, parms={}
	send_frame "SEND", parms.merge( :destination=>destination ), body.to_s
end

#send_frame(verb, headers = {}, body = "") ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/protocols/stomp.rb', line 75

def send_frame verb, headers={}, body=""
	ary = [verb, "\n"]
	headers.each {|k,v| ary << "#{k}:#{v}\n" }
	ary << "content-length: #{body.to_s.length}\n"
	ary << "content-type: text/plain; charset=UTF-8\n"
	ary << "\n"
	ary << body.to_s
	ary << "\0"
	send_data ary.join
end

#subscribe(dest, ack = false) ⇒ Object



120
121
122
# File 'lib/protocols/stomp.rb', line 120

def subscribe dest, ack=false
	send_frame "SUBSCRIBE", {:destination=>dest, :ack=>(ack ? "client" : "auto")}
end