Sha256: 4b4d99bb2d25780e5f3ec7100cee8fd68fade9bbc08fed1e37e914fbb07b182e

Contents?: true

Size: 1.79 KB

Versions: 28

Compression:

Stored size: 1.79 KB

Contents

# -*- encoding: utf-8 -*-

#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
#
if Kernel.respond_to?(:require_relative)
  require_relative("./stomp11_common")
else
  $LOAD_PATH << File.dirname(__FILE__)
  require "stomp11_common"
end
include Stomp11Common
#
# == Stomp 1.1 Receive Example 2
#
# Purpose: to demonstrate receiving messages using Stomp 1.1, and using
# 'ack => client'.
#
class Receive11Example2
  # Initialize.
  def initialize
  end
  # Run example.
  def run
    conn = get_connection() # Use helper method to obtain a Stomp#connection
    raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
    #
    qname = "/queue/nodea.nodeb.nodec"
    #
    uuid = conn.uuid()
    puts "Subscribe id: #{uuid}"
    #
    # Subscribe with client ack mode
    #
    conn.subscribe qname, {'id' => uuid, 'ack' => 'client'} #
    #
    # Once you have subscribed, you may receive as usual
    #
    1.upto(nmsgs()) do
      received = conn.receive
      puts "Received data: #{received.body}"
      #
      # We want now to ACK this message.  In Stomp 1.0, a 'message-id' header was
      # required for the ACK.  In Stomp 1.1, and additional header is required:
      #
      # * 'subscription' => id
      #
      msgid = received.headers['message-id']
      #
      # What you cannot do:
      #
      begin
        conn.ack msgid
      rescue RuntimeError => sre
        puts "Rescue: #{sre}, #{sre.message}"
      end
      #
      # Try a valid 1.1 ACK
      #
      conn.ack msgid, {'subscription' => uuid}
      puts "ACK - msgid: #{msgid}, subscription: #{uuid}"
    end
    #
    # Unsubscribe
    #
    conn.unsubscribe qname, {}, uuid # Second style
    #
    # And finally, disconnect.
    #
    conn.disconnect
  end
end
#
e = Receive11Example2.new
e.run

Version data entries

28 entries across 26 versions & 2 rubygems

Version Path
stomp-1.4.4 examples/get11conn_ex2.rb
stomp-1.4.3 examples/get11conn_ex2.rb
stomp-1.4.2 examples/get11conn_ex2.rb
stomp-1.4.1 examples/get11conn_ex2.rb
stomp-1.4.0 examples/get11conn_ex2.rb
stomp-1.3.5 examples/get11conn_ex2.rb
stomp-1.3.4 examples/get11conn_ex2.rb
stomp-1.3.3 examples/get11conn_ex2.rb
stomp-1.3.2 examples/get11conn_ex2.rb
stomp-1.3.1 examples/get11conn_ex2.rb
stomp-1.3.0 examples/get11conn_ex2.rb
stomp-1.2.16 examples/get11conn_ex2.rb
stomp-1.2.14 examples/get11conn_ex2.rb
stomp-1.2.13 examples/get11conn_ex2.rb
stomp-1.2.12 examples/get11conn_ex2.rb
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/stomp-1.2.8/examples/get11conn_ex2.rb
stomp-1.2.11 examples/get11conn_ex2.rb
stomp-1.2.10 examples/get11conn_ex2.rb
torquebox-console-0.2.5 vendor/bundle/ruby/1.8/gems/stomp-1.2.8/examples/get11conn_ex2.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/stomp-1.2.8/examples/get11conn_ex2.rb