@@ -287,55 +287,49 @@ isopen(c::MessageChannel) = isopen(c.conn) && (c.id in keys(c.conn.channels))
287
287
get_property (c:: MessageChannel , s:: Symbol , default) = get_property (c. conn, s, default)
288
288
get_property (c:: Connection , s:: Symbol , default) = get (c. properties, s, default)
289
289
290
- send (c:: MessageChannel , f, msgframes:: Vector = []) = send (c. conn, f, msgframes)
291
- function send (c:: Connection , f, msgframes:: Vector = [])
292
- # uncomment to enable synchronization (not required till we have preemptive tasks or threads)
293
- @debug (" queing messageframes" , nframes= length (msgframes))
294
- lck = take! (c. sendlck)
290
+ with_sendlock (f, c:: MessageChannel ) = with_sendlock (f, c. conn)
291
+ with_sendlock (f, c:: Connection ) = with_sendlock (f, c. sendlck)
292
+ function with_sendlock (f, sendlck:: Channel{UInt8} )
293
+ lck = take! (sendlck)
295
294
try
296
- put! (c. sendq, TAMQPGenericFrame (f))
297
- for m in msgframes
298
- put! (c. sendq, TAMQPGenericFrame (m))
299
- end
295
+ f ()
300
296
finally
301
- @debug (" queued messageframes" , nqueued= length (c. sendq. data))
302
- put! (c. sendlck, lck)
297
+ put! (sendlck, lck)
303
298
end
304
- nothing
305
299
end
306
- function send (c:: MessageChannel , payload:: TAMQPMethodPayload , msg:: Union{Message, Nothing} = nothing )
307
- @debug (" sending" , methodname= method_name (payload), hascontent= (msg != = nothing ))
300
+ send (c:: MessageChannel , f) = send (c. conn, f)
301
+ send (c:: Connection , f) = put! (c. sendq, TAMQPGenericFrame (f))
302
+ function send (c:: MessageChannel , payload:: TAMQPMethodPayload )
303
+ @debug (" sending without content" , methodname= method_name (payload))
304
+ frameprop = TAMQPFrameProperties (c. id,0 )
305
+ send (c, TAMQPMethodFrame (frameprop, payload))
306
+ end
307
+ function send (c:: MessageChannel , payload:: TAMQPMethodPayload , msg:: Message )
308
+ @debug (" sending with content" , methodname= method_name (payload))
308
309
frameprop = TAMQPFrameProperties (c. id,0 )
309
- if msg != = nothing
310
- msgframes = []
311
- message = msg
310
+ framemax = c. conn. framemax
311
+ if framemax <= 0
312
+ errormsg = (c. conn. state == CONN_STATE_OPEN) ? " Unexpected framemax ($framemax ) value for connection" : " Connection closed"
313
+ throw (AMQPClientException (errormsg))
314
+ end
312
315
313
- # send message header frame
314
- hdrpayload = TAMQPHeaderPayload (payload. class, message)
315
- push! (msgframes, TAMQPContentHeaderFrame (frameprop, hdrpayload))
316
+ with_sendlock (c) do
317
+ send (c, TAMQPMethodFrame (frameprop, payload))
318
+ hdrpayload = TAMQPHeaderPayload (payload. class, msg)
319
+ send (c, TAMQPContentHeaderFrame (frameprop, hdrpayload))
316
320
317
321
# send one or more message body frames
318
322
offset = 1
319
- msglen = length (message. data)
320
- framemax = c. conn. framemax
321
- if framemax <= 0
322
- errormsg = (c. conn. state == CONN_STATE_OPEN) ? " Unexpected framemax ($framemax ) value for connection" : " Connection closed"
323
- throw (AMQPClientException (errormsg))
324
- end
325
-
323
+ msglen = length (msg. data)
324
+ @debug (" sending message with content body" , msglen)
326
325
while offset <= msglen
327
326
msgend = min (msglen, offset + framemax - 1 )
328
- bodypayload = TAMQPBodyPayload (message . data[offset: msgend])
327
+ bodypayload = TAMQPBodyPayload (msg . data[offset: msgend])
329
328
offset = msgend + 1
330
- @debug (" sending" , msglen, offset)
331
- push! (msgframes , TAMQPContentBodyFrame (frameprop, bodypayload))
329
+ @debug (" sending content body frame " , msglen, offset)
330
+ send (c , TAMQPContentBodyFrame (frameprop, bodypayload))
332
331
end
333
-
334
- send (c, TAMQPMethodFrame (frameprop, payload), msgframes)
335
- else
336
- send (c, TAMQPMethodFrame (frameprop, payload))
337
332
end
338
- @debug (" sent" , methodname= method_name (payload))
339
333
end
340
334
341
335
# ----------------------------------------
0 commit comments