Class: Connection11Example2

### Home Classes Methods

### In Files

- examples/conn11_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.

# Connection11Example2

## Stomp 1.1 Connection Example 2

Purpose: to demonstrate a connect and disconnect sequence using Stomp 1.1.

This example is like the 'conn11_ex1.rb' example except that a 'hashed' connect request is made.

### Public Class Methods

new() click to toggle source

Initialize.

    # File examples/conn11_ex2.rb, line 24
    def initialize
    end

### Public Instance Methods

run() click to toggle source

Run example.

    # File examples/conn11_ex2.rb, line 27
    def run
      # Create connection headers
      # =========================
      #
      # The two headers used here are _required_ by the specification.
      #
      conn_hdrs = {"accept-version" => "1.1",    # Demand a 1.1 connection (use a CSV list if you will consider multiple versions)
        "host" => virt_host,                 # The 1.1 vhost (could be different than connection host)
      }                                      # No heartbeats here:  there will be none for this connection
      #
      # Create the connect hash.
      # ========================
      #
      conn_hash = { :hosts => [
          {:login => login, :passcode => passcode, :host => host, :port => port},
        ],
        :reliable => false, # Override default
        :connect_headers => conn_hdrs,
      }
      #
      # Get a connection
      # ================
      #
      conn = Stomp::Connection.new(conn_hash)
      puts "Connection complete"
      #
      # Let's just do some sanity checks, and look around.
      #
      raise "Connection failed!!" unless conn.open?
      #
      # Is this really a 1.1 conection? ('protocol' is a read only connection
      # instance variable. The value will be '1.0' for those types of connections.)
      #
      raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
      #
      # The broker _could_ have returned an ERROR frame (unlikely).
      #
      raise "Connect error: #{conn.connection_frame.body}" if conn.connection_frame.command == Stomp::CMD_ERROR
      #
      # Examine the CONNECT response (the connection_frame).
      #
      puts "Connected Headers required to be present:"
      puts "Connect version - \t#{conn.connection_frame.headers['version']}"
      puts
      puts "Connected Headers that are optional:"
      puts "Connect server - \t\t#{conn.connection_frame.headers['server']}"
      puts "Session ID - \t\t\t#{conn.connection_frame.headers['session']}"
      puts "Server requested heartbeats - \t#{conn.connection_frame.headers['heart-beat']}"
      #
      # Finally disconnect
      # ==================
      #
      conn.disconnect   # Business as usual, just like 1.0
      puts "Disconnect complete"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.