|
NAMENet::STOMP::Client::Frame - Frame support for Net::STOMP::ClientSYNOPSISuse Net::STOMP::Client::Frame qw(); # create a connection frame $frame = Net::STOMP::Client::Frame->new( command => "CONNECT", headers => { login => "guest", passcode => "guest", }, ); # get the command $cmd = $frame->command(); # set the body $frame->body("...some data..."); # directly get a header field $msgid = $frame->header("message-id"); DESCRIPTIONThis module provides an object oriented interface to manipulate STOMP frames.A frame object has the following attributes: "command", "headers" and "body_reference". The "headers" attribute must be a reference to a hash of header key/value pairs. The body is usually manipulated by reference to avoid string copies. METHODSThis module provides the following methods:
FUNCTIONSThis module provides the following functions (which are not exported):
VARIABLESThis module uses the following global variables (which are not exported):
FRAME PARSINGThe parse() function can be used to parse a frame without decoding it.It takes as input a binary string reference (to avoid string copies) and an optional state (a hash reference). It parses the string to find out where the different parts of the frames are and it updates its state (if given). It returns false if the string does not hold a complete frame or a hash reference if a complete frame is present. This hash is in fact the same thing as the state and it contains the following keys:
Here is how this could be used: $data = "... read from socket or file ..."; $info = Net::STOMP::Client::Frame::parse(\$data); if ($info) { # extract interesting frame parts $command = substr($data, $info->{command_idx}, $info->{command_len}); # remove the frame from the buffer substr($data, 0, $info->{total_len}) = ""; } CONTENT LENGTHThe "content-length" header is special because it is sometimes used to indicate the length of the body but also the JMS type of the message in ActiveMQ as per <http://activemq.apache.org/stomp.html>.If you do not supply a "content-length" header, following the protocol recommendations, a "content-length" header will be added if the frame has a body. If you do supply a numerical "content-length" header, it will be used as is. Warning: this may give unexpected results if the supplied value does not match the body length. Use only with caution! Finally, if you supply an empty string as the "content-length" header, it will not be sent, even if the frame has a body. This can be used to mark a message as being a TextMessage for ActiveMQ. Here is an example of this: $stomp->send( "destination" => "/queue/test", "body" => "hello world!", "content-length" => "", ); ENCODINGThe STOMP 1.0 specification does not define which encoding should be used to serialize frames. So, by default, this module assumes that what has been given by the user or by the server is a ready-to-use sequence of bytes and it does not perform any further encoding or decoding.If $Net::STOMP::Client::Frame::StrictEncode is true, all encoding and decoding operations will be stricter and will report a fatal error when given malformed input. This is done by using the Encode::FB_CROAK flag instead of the default Encode::FB_DEFAULT. N.B.: Perl's standard Encode module is used for all encoding/decoding operations. MESSAGING ABSTRACTIONIf the Messaging::Message module is available, the following method and function are available too:
Here is how they could be used: # frame to message $frame = $stomp->wait_for_frames(timeout => 1); if ($frame) { $message = $frame->messagify(); ... } # message to frame $frame = Net::STOMP::Client::Frame::demessagify($message); $stomp->send_frame($frame); Note: in both cases, string copies are avoided so both objects will share the same header hash and body string. Therefore modifying one may also modify the other. Clone (copy) the objects if you do not want this behavior. COMPLIANCESTOMP 1.0 has several ambiguities and this module does its best to work "as expected" in these gray areas.STOMP 1.1 and STOMP 1.2 are much better specified and this module should be fully compliant with these STOMP specifications with only one exception: by default, this module is permissive and allows malformed encoded data (this is the same default as the Encode module itself); to be more strict, set $Net::STOMP::Client::Frame::StrictEncode to true (as explained above). SEE ALSOEncode, Messaging::Message, Net::STOMP::Client.AUTHORLionel Cons <http://cern.ch/lionel.cons>Copyright (C) CERN 2010-2017
Visit the GSP FreeBSD Man Page Interface. |