Class: Receive11Example2

### Home Classes Methods

### In Files

- examples/get11conn_ex2.rb

### Parent

Object

### Methods

- ::new
- #run

### Files

- CHANGELOG.rdoc
- LICENSE

### Class/Module Index

Quicksearch

- Stomp
- Stomp::Client
- Stomp::Connection
- Stomp::Error
- Stomp::Error::BrokerException
- Stomp::Error::ConnectReadTimeout
- Stomp::Error::DuplicateSubscription
- Stomp::Error::InvalidFormat
- Stomp::Error::InvalidHeartBeatHeaderError
- Stomp::Error::InvalidMessageLength
- Stomp::Error::InvalidServerCommand
- Stomp::Error::LoggerConnectionError
- Stomp::Error::MalformedFailoverOptionsError
- Stomp::Error::MaxReconnectAttempts
- Stomp::Error::MessageIDRequiredError
- Stomp::Error::NilMessageError
- Stomp::Error::NoCurrentConnection
- Stomp::Error::PacketParsingTimeout
- Stomp::Error::ProducerFlowControlException
- Stomp::Error::ProtocolError11p
- Stomp::Error::ProtocolErrorConnect
- Stomp::Error::ProtocolErrorEmptyHeaderKey
- Stomp::Error::ProtocolErrorEmptyHeaderValue
- Stomp::Error::ProtocolException
- Stomp::Error::ReadReceiptTimeoutException
- Stomp::Error::SSLClientParamsError
- Stomp::Error::SSLNoCertFileError
- Stomp::Error::SSLNoKeyFileError
- Stomp::Error::SSLNoTruststoreFileError
- Stomp::Error::SSLUnreadableCertFileError
- Stomp::Error::SSLUnreadableKeyFileError
- Stomp::Error::SSLUnreadableTruststoreFileError
- Stomp::Error::SocketOpenTimeout
- Stomp::Error::StartTimeoutException
- Stomp::Error::StompException
- Stomp::Error::StompServerError
- Stomp::Error::SubscriptionRequiredError
- Stomp::Error::UTF8ValidationError
- Stomp::Error::UnsupportedProtocolError
- Stomp::HeaderCodec
- Stomp::Message
- Stomp::NullLogger
- Stomp::SSLParams
- Client11Example1
- Client11PutGet1
- Connection11Example1
- Connection11Example2
- ExampleConsumer
- ExamplePublisher
- ExampleRubyCiphers
- ExampleSSL1
- ExampleSSL1C
- ExampleSSL2
- ExampleSSL2C
- ExampleSSL3
- ExampleSSL3C
- ExampleSSL4
- ExampleSSL4C
- ExampleSSLCtxOptions
- ExampleSSLNewParm
- ExampleTopicConsumer
- ExampleTopicPublisher
- Hash
- HeartBeatExample1
- LoggerExample
- Object
- Publish11Example1
- Receive11Example1
- Receive11Example2
- RepeatedHeadersExample
- SSLLoggerExample
- Slogger
- Stomp11Common
- TestAnonymous
- TestBase
- TestClient
- TestConnection
- TestConnection1P
- TestMessage
- TestSSL
- TestURLLogins
- Tlogger

No matching classes.

# Receive11Example2

## Stomp 1.1 Receive Example 2

Purpose: to demonstrate receiving messages using Stomp 1.1, and using 'ack => client'.

### Public Class Methods

new() click to toggle source

Initialize.

    # File examples/get11conn_ex2.rb, line 21
    def initialize
    end

### Public Instance Methods

run() click to toggle source

Run example.

    # File examples/get11conn_ex2.rb, line 24
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.