Module: OnStomp::Interfaces::FrameMethods

Overview

Mixin for clients to provide methods that create and transmit STOMP frames.

Instance Method Summary collapse

Instance Method Details

#abort(tx_id, headers = {}) ⇒ OnStomp::Components::Frame

Transmits an ABORT frame generated by the client’s connection to rollback a transaction.

Parameters:

  • tx_id (String)

    identifier for the transaction

  • headers ({#to_sym => #to_s}) (defaults to: {})

    additional headers to include in the frame

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support ABORT frames

See Also:



100
101
102
# File 'lib/onstomp/interfaces/frame_methods.rb', line 100

def abort tx_id, headers={}
  transmit connection.abort_frame(tx_id, headers)
end

#ack(message_frame, headers = {}) ⇒ OnStomp::Components::Frame #ack(message_id, headers = {}) ⇒ OnStomp::Components::Frame #ack(message_id, subscription_id, heders = {}) ⇒ OnStomp::Components::Frame

Transmits an ACK frame generated by the client’s connection.

Overloads:

  • #ack(message_frame, headers = {}) ⇒ OnStomp::Components::Frame
    Note:

    Users should use this form whenever possible as it will work with STOMP 1.0 and 1.1 connections.

    Parameters:

    • message_frame (OnStomp::Components::Frame)

      the MESSAGE frame to acknowledge.

    • headers ({#to_sym => #to_s}) (defaults to: {})

      additional headers to include in the frame

  • #ack(message_id, headers = {}) ⇒ OnStomp::Components::Frame
    Note:

    This form will raise an ArgumentError with STOMP 1.1 connections as a subscription ID is also required to ACK a received MESSAGE.

    Parameters:

    • message_id (String)

      message-id header of MESSAGE frame to acknowledge.

    • headers ({#to_sym => #to_s}) (defaults to: {})

      additional headers to include in the frame

  • #ack(message_id, subscription_id, heders = {}) ⇒ OnStomp::Components::Frame
    Note:

    This form should be used with STOMP 1.1 connections when it is not possible to provide the actual MESSAGE frame.

    Parameters:

    • message_id (String)

      message-id header of MESSAGE frame to acknowledge.

    • subscription_id (String)

      subscription header of MESSAGE frame to acknowledge.

    • headers ({#to_sym => #to_s})

      additional headers to include in the frame

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support ACK frames

See Also:



157
158
159
# File 'lib/onstomp/interfaces/frame_methods.rb', line 157

def ack *args
  transmit connection.ack_frame(*args)
end

#beatOnStomp::Components::Frame

Transmits a client heartbeat frame generated by the client’s connection.

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support heartbeat frames



187
188
189
# File 'lib/onstomp/interfaces/frame_methods.rb', line 187

def beat
  transmit connection.heartbeat_frame
end

#begin(tx_id, headers = {}) ⇒ OnStomp::Components::Frame

Transmits a BEGIN frame generated by the client’s connection to start a transaction.

Parameters:

  • tx_id (String)

    identifier for the transaction

  • headers ({#to_sym => #to_s}) (defaults to: {})

    additional headers to include in the frame

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support BEGIN frames

See Also:



86
87
88
# File 'lib/onstomp/interfaces/frame_methods.rb', line 86

def begin tx_id, headers={}
  transmit connection.begin_frame(tx_id, headers)
end

#commit(tx_id, headers = {}) ⇒ OnStomp::Components::Frame

Transmits a COMMIT frame generated by the client’s connection to complete a transaction.

Parameters:

  • tx_id (String)

    identifier for the transaction

  • headers ({#to_sym => #to_s}) (defaults to: {})

    additional headers to include in the frame

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support COMMIT frames

See Also:



114
115
116
# File 'lib/onstomp/interfaces/frame_methods.rb', line 114

def commit tx_id, headers={}
  transmit connection.commit_frame(tx_id, headers)
end

#disconnect(headers = {}) ⇒ OnStomp::Components::Frame

Transmits a DISCONNECT frame generated by the client’s connection to end the STOMP session.

Parameters:

  • headers ({#to_sym => #to_s}) (defaults to: {})

    additional headers to include in the frame

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support DISCONNECT frames



125
126
127
# File 'lib/onstomp/interfaces/frame_methods.rb', line 125

def disconnect headers={}
  transmit connection.disconnect_frame headers
end

#nack(message_frame, headers = {}) ⇒ OnStomp::Components::Frame #nack(message_id, subscription_id, heders = {}) ⇒ OnStomp::Components::Frame

Transmits a NACK frame generated by the client’s connection.

Overloads:

  • #nack(message_frame, headers = {}) ⇒ OnStomp::Components::Frame

    Generates a NACK frame for the given MESSAGE frame.

    Parameters:

    • message_frame (OnStomp::Components::Frame)

      the MESSAGE frame to un-acknowledge.

    • headers ({#to_sym => #to_s}) (defaults to: {})

      additional headers to include in the frame

  • #nack(message_id, subscription_id, heders = {}) ⇒ OnStomp::Components::Frame

    Parameters:

    • message_id (String)

      message-id header of MESSAGE frame to un-acknowledge.

    • subscription_id (String)

      subscription header of MESSAGE frame to un-acknowledge.

    • headers ({#to_sym => #to_s})

      additional headers to include in the frame

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support NACK frames

See Also:



179
180
181
# File 'lib/onstomp/interfaces/frame_methods.rb', line 179

def nack *args
  transmit connection.nack_frame(*args)
end

#send(dest, body, headers = {}) {|receipt| ... } ⇒ OnStomp::Components::Frame Also known as: puts

Transmits a SEND frame generated by the client’s connection

Parameters:

  • dest (String)

    destination for the frame

  • body (String)

    body of the frame

  • headers ({#to_sym => #to_s}) (defaults to: {})

    additional headers to include in the frame

Yields:

  • (receipt)

    block to invoke when a RECEIPT frame is received for the transmitted SEND frame

Yield Parameters:

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support SEND frames



17
18
19
# File 'lib/onstomp/interfaces/frame_methods.rb', line 17

def send dest, body, headers={}, &cb
  transmit connection.send_frame(dest, body, headers), :receipt => cb
end

#subscribe(dest, headers = {}) {|message| ... } ⇒ OnStomp::Components::Frame

Transmits a SUBSCRIBE frame generated by the client’s connection. Depending upon the connection, a subscription can be set to various MESSAGE acknowledgement modes by setting the :ack header. STOMP 1.0 and STOMP 1.1 connections support:

  • :ack => ‘auto’ The broker assumes that MESSAGE frames received through the subscription have been properly received, the client should NOT attempt to ACK (or NACK) any of the messages.

  • :ack => ‘client’ The broker assumes that MESSAGE frames should be acknowledged by the client through the use of ACK frames.

STOMP 1.1 connections support:

  • :ack => ‘client-individual’ Upon receiving an ACK frame for a MESSAGE frame, some brokers will mark the MESSAGE frame and all those sent to the client before it as acknowledged. This mode indicates that each MESSAGE frame must be acknowledged by its own ACK frame for the broker can assume the MESSAGE frame has been received by the client.

Parameters:

  • dest (String)

    destination for the frame

  • headers ({#to_sym => #to_s}) (defaults to: {})

    additional headers to include in the frame

Yields:

  • (message)

    block to invoke for every MESSAGE frame received on the subscription

Yield Parameters:

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support SUBSCRIBE frames

See Also:



53
54
55
# File 'lib/onstomp/interfaces/frame_methods.rb', line 53

def subscribe dest, headers={}, &cb
  transmit connection.subscribe_frame(dest, headers), :subscribe => cb
end

#unsubscribe(subscribe_frame, headers = {}) ⇒ OnStomp::Components::Frame #unsubscribe(id, headers = {}) ⇒ OnStomp::Components::Frame

Transmits an UNSUBSCRIBE frame generated by the client’s connection.

Overloads:

  • #unsubscribe(subscribe_frame, headers = {}) ⇒ OnStomp::Components::Frame

    Generates an UNSUBSCRIBE frame to match the given SUBSCRIBE frame

    Parameters:

    • subscribe_frame (OnStomp::Components::Frame)
    • headers ({#to_sym => #to_s}) (defaults to: {})

      optional headers to include in the UNSUBSCRIBE frame

  • #unsubscribe(id, headers = {}) ⇒ OnStomp::Components::Frame

    Generates an UNSUBSCRIBE frame with the given id

    Parameters:

    • id (String)
    • headers ({#to_sym => #to_s}) (defaults to: {})

      optional headers to include in the UNSUBSCRIBE frame

Returns:

Raises:

  • OnStomp::UnsupportedCommandError if the connection does not support UNSUBSCRIBE frames

See Also:



72
73
74
# File 'lib/onstomp/interfaces/frame_methods.rb', line 72

def unsubscribe frame_or_id, headers={}
  transmit connection.unsubscribe_frame(frame_or_id, headers)
end