[DRE-commits] [SCM] ruby-stomp.git branch, upstream, updated. upstream/1.2.2-1-g3f487ef
Jonas Genannt
jonas at brachium-system.net
Thu Jul 5 15:15:41 UTC 2012
The following commit has been merged in the upstream branch:
commit 3f487efc53a6bf9296a62a9b27d7e98bd3755fab
Author: Jonas Genannt <jonas at brachium-system.net>
Date: Thu Jul 5 17:10:08 2012 +0200
Adding upstream version 1.2.4.
diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc
index 2ee6ff2..c5112fc 100644
--- a/CHANGELOG.rdoc
+++ b/CHANGELOG.rdoc
@@ -1,4 +1,24 @@
-== 1.2.2 2012-24-03
+== 1.2.4 20120625
+
+* Add ability for client to request flush on write to the connection (Issue #45)
+* Add ability for client to retrieve heartbeat intervals and counters
+* Fix I/O errors with heartbeats and multithreaded clients (Issue #46)
+* Enhance tests for heartbeats
+* Correct typos and clarify comments in many examples
+
+== 1.2.3 20120616
+
+* Fix UnsupportedProtocol on connect to a 1.0 broker
+* Add Client#poll method
+* Add help to stompcat and catstomp
+* Allow password to be set for private SSL key
+* Update comments to reflect new repository URL
+* Reformat changelog dates to ISO8601
+* Fix SSL connection failures using JRuby
+* Use symbols, not strings for all header keys
+* Add IPV6 to IPV4 failover for dual homed systems when requested
+
+== 1.2.2 20120324
* Major performance improvement for read of messages without content-length header
* Correct Stomp 1.1 failing test
@@ -8,16 +28,16 @@
* Allow SSL file checks before connect using SSLParams.new(:fsck => true, ...)
* Correct a test for Windows compatibility
-== 1.2.1 2012-13-03
+== 1.2.1 20120313
-* Robust SSL certificate support. See examples and: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+* Robust SSL certificate support. See examples and: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
* Really remove the deprecated #send methods
* Fix exception in Stomp 1.1 code when headers are frozen
* Revert 245e734a0. See ce8335fb2f for details. Fixes broken Connection#poll.
* Add reconnection attempts to callback logging.
* Add SSL specific connection information to callback logging.
-== 1.2.0 2011-14-12
+== 1.2.0 20111214
* Stomp 1.1 protocol support. A significant change. Please test existing 1.0 code well. See the examples directory for 1.1 examples.
* Accept :reliable in a Stomp::Client connection hash
@@ -27,14 +47,14 @@
* Fix subscription id in find_listener
* Start to bootstrap STOMP 1.1 support
-== 1.1.10 2011-07-11
+== 1.1.10 20111107
* Fixes for JRuby support
* Fix EOF error on disconnect
* Refactoring and additional test
* Set up tests for use of RabbitMQ
-== 1.1.9 2011-15-06
+== 1.1.9 20110615
* Support wildcard destinations
* Handle subscribe with string or symbol ID
@@ -45,7 +65,7 @@
* Add optional callback logging. See the examples install directory, files logexamp.rb and slogger.rb
* Correct date stamps in this file
-== 1.1.8 2011-16-03
+== 1.1.8 20110316
* Set KEEPALIVE on connection socket options
* Attempt to support JRuby more robustly (poll remains broken)
@@ -56,23 +76,23 @@
* Allow connection to hosts with a - (dash) in the host name
* Add limit parameter to thread joins
-== 1.1.7 2011-09-01
+== 1.1.7 20110109
* Binary parse of raw STOMP frame
* Fix broken tests on Ruby 1.9.2
-== 1.1.6 2010-10-06
+== 1.1.6 20100610
* Fixed multi-thread app hanging
-== 1.1.5 2010-17-03
+== 1.1.5 20100317
* Added publish method (send is now deprecated)
* Changes on Rake File
* Added original_destination header to unreceive
* suppress content length header is send on the message for future handling (like unreceive)
-== 1.1.4 2010-21-01
+== 1.1.4 20100121
* Added unreceive message method that sends the message back to its queue or to the
dead letter queue, depending on the :max_redeliveries option, similar to a13m one.
@@ -87,13 +107,13 @@
* Added connection_frame accessor
* Added disconnect receipt
-== 1.1.3 2009-24-11
+== 1.1.3 20091124
* Failover support
* SSL support
* Stomp::Connection and Stomp::Client accept a hash on their constructor
-== 1.1 2009-27-02
+== 1.1 20090227
* Ruby 1.9 Support
* Add support for connect_headers, to control the CONNECT command.
@@ -101,7 +121,7 @@
* Better test coverage
* General code cleanup.
-== 1.0.6 2008-05-08
+== 1.0.6 20080805
* Whitespace cleanup
* Refactored Rakefile and added stomp.gemspec for GitHub friendliness.
@@ -113,8 +133,33 @@
* Created initial RSpec specs which stub/mock objects and should not require a running
Stomp server instance.
-== v1.0.5
+== v1.0.5 20070201
+
+* better url parsing
+* git-svn-id: http://svn.codehaus.org/stomp/ruby/trunk@48 fd4e7336-3dff-0310-b68a-b6615a75f13b
+
+== v1.0.4 20070115
+
+* Allow URL style connections descriptors
+* git-svn-id: http://svn.codehaus.org/stomp/ruby/trunk@44 fd4e7336-3dff-0310-b68a-b6615a75f13b
+
+== v1.0.3 20070114
+
+* Additional fixes for reliable by Andrew Kuklewicz
+* git-svn-id: http://svn.codehaus.org/stomp/ruby/trunk@42 fd4e7336-3dff-0310-b68a-b6615a75f13b
+
+== v1.0.2 20060922
+
+* Moving ruby so we can tag it ;-)
+* git-svn-id: http://svn.codehaus.org/stomp/ruby/trunk@37 fd4e7336-3dff-0310-b68a-b6615a75f13b
+
+== v1.0.1 20051217
+
+* Increment version
+* git-svn-id: http://svn.codehaus.org/stomp/trunk/ruby@24 fd4e7336-3dff-0310-b68a-b6615a75f13b
+
+== v1.0.0 20051015
-SVN rev 86 clone from http://svn.codehaus.org/stomp/ruby/trunk
+* works in repl, getting messages in weird order or dupes in test, but unable to isolate so far =(
+* git-svn-id: http://svn.codehaus.org/stomp/trunk/ruby@20 fd4e7336-3dff-0310-b68a-b6615a75f13b
-git-svn-id: http://svn.codehaus.org/stomp/ruby/trunk@86 fd4e7336-3dff-0310-b68a-b6615a75f13b
diff --git a/README.rdoc b/README.rdoc
index 87b3f9c..104f771 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -1,7 +1,6 @@
==README
-* (https://github.com/morellon/stomp/)
-* (http://gitorious.org/projects/stomp/)
+* (https://github.com/stompgem/stomp/)
===Overview
@@ -11,6 +10,8 @@ An implementation of the Stomp protocol for Ruby. See:
===New
+* Gem version 1.2.2. Stomp 1.1 heartbeat fix, autoflush capability, miscellaneous fixes
+* Gem version 1.2.3. Miscellaneous fixes, see changelog for details.
* Gem version 1.2.2. Performance and more SSL enhancements.
* Full support of SSL certificates is announced as of gem version 1.2.1.
* Support of Stomp protocol level 1.1 is announced as of gem version 1.2.0.
@@ -46,6 +47,7 @@ See the change log for details.
],
# These are the default parameters, don't need to be set
+ :reliable => true, # true for hash login
:initial_reconnect_delay => 0.01,
:max_reconnect_delay => 30.0,
:use_exponential_back_off => true,
@@ -72,8 +74,7 @@ Up until March 2009 the project was maintained and primarily developed by Brian
===Source Code and Project URLs
- https://github.com/morellon/stomp/
- http://gitorious.org/projects/stomp/
+ https://github.com/stompgem/stomp/
===Stomp Protocol Information :
@@ -83,12 +84,12 @@ Up until March 2009 the project was maintained and primarily developed by Brian
The following people have contributed to Stomp:
-* Brian McCaliister
+* Brian McCallister
* Glenn Rempe <glenn at rempe.us>
* jstrachan
* Marius Mathiesen <marius.mathiesen at gmail.com>
* Johan S√∏rensen <johan at johansorensen.com>
-* Thiago Morello <morellon at gmail.com>
+* Thiago Morello <stompgem at gmail.com>
* Guy M. Allard
* kookster
* Tony Garnock-Jones <tonyg at lshift.net>
@@ -104,15 +105,7 @@ The following people have contributed to Stomp:
* R.I. Pienaar
* tworker
* James Pearson
-
-= Announcements
-
-In the next version of the gem, the dates in CHANGELOG.rdoc will be changed from:
-
-* yyyy-dd-mm
-
-to:
-
-* ISO8601 format (yyyymmdd)
-
+* Craig
+* Tommy Bishop
+* Jeremy Gailor
diff --git a/Rakefile b/Rakefile
index 59d8027..7ea82fd 100644
--- a/Rakefile
+++ b/Rakefile
@@ -33,7 +33,7 @@ begin
gem.description = %Q{Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge.}
gem.email = ["brianm at apache.org", 'marius at stones.com', 'morellon at gmail.com',
'allard.guy.m at gmail.com' ]
- gem.homepage = "https://github.com/morellon/stomp"
+ gem.homepage = "https://github.com/stompgem/stomp"
gem.authors = ["Brian McCallister", 'Marius Mathiesen', 'Thiago Morello',
'Guy M. Allard']
gem.add_development_dependency "rspec", '>= 2.3'
diff --git a/bin/catstomp b/bin/catstomp
index 976de80..746b3ef 100755
--- a/bin/catstomp
+++ b/bin/catstomp
@@ -28,6 +28,25 @@ require 'stomp'
#
begin
+ if ARGV[0] == '-h' || ARGV[0] == '--help'
+ $stdout.puts
+ $stdout.puts 'Usage: catstomp DESTINATION'
+ $stdout.puts
+ $stdout.puts 'Publishes STDIN to the desired stomp destination'
+ $stdout.puts
+ $stdout.puts 'Example: ls | catstomp /topic/foo'
+ $stdout.puts
+ $stdout.puts 'Defaults:'
+ $stdout.puts "DESTINATION\t/topic/default"
+ $stdout.puts "STOMP_HOST\tlocalhost"
+ $stdout.puts "STOMP_PORT\t61613"
+ $stdout.puts "STOMP_USER"
+ $stdout.puts "STOMP_PASSWORD"
+ $stdout.puts
+ $stdout.puts 'You can override the stomp host, port, user, or password through environment variables'
+ exit 0
+ end
+
@port = 61613
@host = "localhost"
@user = ENV["STOMP_USER"];
diff --git a/bin/stompcat b/bin/stompcat
index e51d0c6..006a910 100755
--- a/bin/stompcat
+++ b/bin/stompcat
@@ -28,6 +28,25 @@ require 'stomp'
#
begin
+ if ARGV[0] == '-h' || ARGV[0] == '--help'
+ $stdout.puts
+ $stdout.puts 'Usage: stompcat DESTINATION'
+ $stdout.puts
+ $stdout.puts 'Receives data from a stomp destination and outputs it to STDOUT'
+ $stdout.puts
+ $stdout.puts 'Example: stompcat /topic/foo'
+ $stdout.puts
+ $stdout.puts 'Defaults:'
+ $stdout.puts "DESTINATION\t/topic/default"
+ $stdout.puts "STOMP_HOST\tlocalhost"
+ $stdout.puts "STOMP_PORT\t61613"
+ $stdout.puts "STOMP_USER\t"
+ $stdout.puts "STOMP_PASSWORD\t"
+ $stdout.puts
+ $stdout.puts 'You can override the host, port, user, or password through environment variables'
+ exit 0
+ end
+
@port = 61613
@host = "localhost"
@user = ENV["STOMP_USER"];
diff --git a/examples/client11_ex1.rb b/examples/client11_ex1.rb
index eeb1ea2..ea392eb 100644
--- a/examples/client11_ex1.rb
+++ b/examples/client11_ex1.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
@@ -13,11 +15,11 @@ include Stomp11Common
# Stomp 1.1 Client Example 1
# ==============================
#
-# Purpose: to demonstrate a clientect and disclientect sequence using Stomp 1.1
-# with the Stomp#client intreface.
+# Purpose: to demonstrate a connect and disconnect sequence using Stomp 1.1
+# with the Stomp#Client interface.
#
-# Note: Stomp#client does not provide a positional set of parameters that
-# contain a 'clientect_headers' parameter. To use the Stomp#client interface
+# Note: Stomp#Client does not provide a positional set of parameters that
+# contain a 'connect_headers' parameter. To use the Stomp#Client interface
# you _must_ use a 'hashed' set of parameters.
#
# Create connection headers
@@ -26,8 +28,8 @@ include Stomp11Common
# The two headers used here are _required_ by the specification.
#
client_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
+ "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.
# ========================
@@ -42,7 +44,7 @@ client_hash = { :hosts => [
# ================
#
client = Stomp::Client.new(client_hash)
-puts "Connection complete"
+puts "Client Connect complete"
#
# Let's just do some sanity checks, and look around.
#
@@ -72,7 +74,7 @@ puts "Server requested heartbeats - \t#{client.connection_frame().headers['heart
# =============
#
client.close # Business as usual, just like 1.0
-puts "Disclientect complete"
+puts "Client close complete"
diff --git a/examples/client11_putget1.rb b/examples/client11_putget1.rb
index 77c9025..ddcc35d 100644
--- a/examples/client11_putget1.rb
+++ b/examples/client11_putget1.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
@@ -26,7 +28,7 @@ client_hash = { :hosts => [
}
#
client = Stomp::Client.new(client_hash)
-puts "Connection complete"
+puts "Client Connect complete"
#
raise "Unexpected protocol level" if client.protocol() != Stomp::SPL_11
#
@@ -51,7 +53,7 @@ raise "Unexpected data" if data != message.body
raise "Bad subscription header" if uuid != message.headers['subscription']
#
client.close # Business as usual, just like 1.0
-puts "Disclientect complete"
+puts "Client close complete"
diff --git a/examples/conn11_ex1.rb b/examples/conn11_ex1.rb
index 0665860..758b919 100644
--- a/examples/conn11_ex1.rb
+++ b/examples/conn11_ex1.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
@@ -15,7 +17,7 @@ include Stomp11Common
#
# Purpose: to demonstrate a connect and disconnect sequence using Stomp 1.1.
#
-# Note: this example assumes that you have at least the 1.1.11 gem release
+# Note: this example assumes that you have at least the 1.2.0 gem release
# installed.
#
# When you:
@@ -45,8 +47,9 @@ include Stomp11Common
#
# * heartbeat request
#
-# Using the stomp gem, you specify this data in the "connect_headers" Hash
-# parameter.
+# Using the stomp gem, you can specify this data in the "connect_headers" Hash
+# parameter or a paramaterized connection request. This example uses a
+# parameterized request.
#
# So .........
#
@@ -63,10 +66,10 @@ conn_hdrs = {"accept-version" => "1.1", # Demand a 1.1 connection (use a CSV
# ================
#
conn = Stomp::Connection.new(login, passcode, host, port, # Normal connect parms
- false, # Not reliable, the default
+ false, # Not reliable, the default for a parameter connection
5, # Connect redelay, the default
conn_hdrs) # The 1.1 connection parameters
-puts "Connection complete"
+puts "Connection connect complete"
#
# Let's just do some sanity checks, and look around.
#
@@ -95,7 +98,7 @@ puts "Server requested heartbeats - \t#{conn.connection_frame.headers['heart-bea
# ==================
#
conn.disconnect # Business as usual, just like 1.0
-puts "Disconnect complete"
+puts "Connection disconnect complete"
diff --git a/examples/conn11_ex2.rb b/examples/conn11_ex2.rb
index 9c1e805..7eb1e73 100644
--- a/examples/conn11_ex2.rb
+++ b/examples/conn11_ex2.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
@@ -33,6 +35,7 @@ conn_hdrs = {"accept-version" => "1.1", # Demand a 1.1 connection (use a CSV
conn_hash = { :hosts => [
{:login => login, :passcode => passcode, :host => host, :port => port},
],
+ :reliable => false, # Override default
:connect_headers => conn_hdrs,
}
#
diff --git a/examples/conn11_hb1.rb b/examples/conn11_hb1.rb
index 36932b9..734e13c 100644
--- a/examples/conn11_hb1.rb
+++ b/examples/conn11_hb1.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
@@ -26,12 +28,12 @@ conn_hdrs = {"accept-version" => "1.1", # 1.1
}
# Create a logger for demonstration purposes
logger = Slogger.new
-# Connect
+# Connect - a paramaterized request.
conn = Stomp::Connection.new(login, passcode, host, port, # Normal connect parms
- false, # Not reliable, the default
- 5, # Connect redelay, the default
- conn_hdrs) # The 1.1 connection parameters
-puts "Connection complete"
+ false, # Not reliable, the default for a paramaterized connection
+ 5, # Connect redelay, the default for a paramaterized connection
+ conn_hdrs) # The 1.1 connection parameters / headers
+puts "Connection connect complete"
#
raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
#
@@ -40,7 +42,7 @@ sleep 65
conn.set_logger(nil) # No logging
#
conn.disconnect # Get out
-puts "Disconnect complete"
+puts "Connection disconnect complete"
diff --git a/examples/get11conn_ex1.rb b/examples/get11conn_ex1.rb
index 980f9fc..e2f7145 100644
--- a/examples/get11conn_ex1.rb
+++ b/examples/get11conn_ex1.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
@@ -26,7 +28,7 @@ raise "Unexpected protocol level" if conn.protocol != Stomp::SPL_11
# * for subscribe, the 'id' header is now _required_
# * for unsubscribe, the 'id' header is now _required_
#
-# The 'id' header specifies a 'subscription id' that must be unique for
+# The 'id' header specifies a 'subscription id' that _must_ be unique for
# the current session.
#
qname = "/queue/nodea.nodeb.nodec"
diff --git a/examples/get11conn_ex2.rb b/examples/get11conn_ex2.rb
index be07098..6023c71 100644
--- a/examples/get11conn_ex2.rb
+++ b/examples/get11conn_ex2.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
diff --git a/examples/logexamp.rb b/examples/logexamp.rb
index 96cffd2..a3d409f 100644
--- a/examples/logexamp.rb
+++ b/examples/logexamp.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
require 'rubygems'
require 'stomp'
require 'logger' # for the 'local' logger
@@ -6,7 +8,7 @@ $:.unshift(File.dirname(__FILE__))
#
require 'slogger'
#
-# A STOMP client program which uses the callback logging facility.
+# A STOMP::Connection program which uses the callback logging facility.
#
llog = Logger::new(STDOUT)
llog.level = Logger::DEBUG
@@ -14,7 +16,6 @@ llog.debug "LE Starting"
# //////////////////////////////////////////////////////////////////////////////
mylog = Slogger::new # The client provided STOMP callback logger
-# -*- encoding: utf-8 -*-
# //////////////////////////////////////////////////////////////////////////////
user = ENV['STOMP_USER'] ? ENV['STOMP_USER'] : 'guest'
diff --git a/examples/logexamp_ssl.rb b/examples/logexamp_ssl.rb
index 9b454c5..3def39b 100644
--- a/examples/logexamp_ssl.rb
+++ b/examples/logexamp_ssl.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
require 'rubygems'
require 'stomp'
require 'logger' # for the 'local' logger
@@ -6,7 +8,7 @@ $:.unshift(File.dirname(__FILE__))
#
require 'slogger'
#
-# A STOMP client program which uses the callback logging facility.
+# A STOMP::Connection program which uses the callback logging facility.
#
llog = Logger::new(STDOUT)
llog.level = Logger::DEBUG
@@ -14,7 +16,6 @@ llog.debug "LESSL Starting"
# //////////////////////////////////////////////////////////////////////////////
mylog = Slogger::new # The client provided STOMP callback logger
-# -*- encoding: utf-8 -*-
# //////////////////////////////////////////////////////////////////////////////
user = ENV['STOMP_USER'] ? ENV['STOMP_USER'] : 'guest'
diff --git a/examples/put11conn_ex1.rb b/examples/put11conn_ex1.rb
index 77a26c6..83b62a6 100644
--- a/examples/put11conn_ex1.rb
+++ b/examples/put11conn_ex1.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
diff --git a/examples/putget11_rh1.rb b/examples/putget11_rh1.rb
index 10f6b1e..fe55650 100644
--- a/examples/putget11_rh1.rb
+++ b/examples/putget11_rh1.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# The current require dance for different Ruby versions.
# Change this to suit your requirements.
diff --git a/examples/slogger.rb b/examples/slogger.rb
index dff0050..70210b5 100644
--- a/examples/slogger.rb
+++ b/examples/slogger.rb
@@ -175,7 +175,7 @@ class Slogger
def on_ssl_connectfail(parms)
begin
@log.debug "SSL Connect Fail Parms #{info(parms)}"
- @log.debug "SSL Connect Fail Excception #{parms[:ssl_exception]}, #{parms[:ssl_exception].message}"
+ @log.debug "SSL Connect Fail Exception #{parms[:ssl_exception]}, #{parms[:ssl_exception].message}"
rescue
@log.debug "SSL Connect Fail oops"
end
diff --git a/examples/ssl_uc1.rb b/examples/ssl_uc1.rb
index 81360e0..5a955c0 100644
--- a/examples/ssl_uc1.rb
+++ b/examples/ssl_uc1.rb
@@ -1,19 +1,35 @@
+# -*- encoding: utf-8 -*-
+
#
-# Reference: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
require "rubygems"
require "stomp"
#
-# SSL Use Case 1
+# SSL Use Case 1 - server does *not* authenticate client, client does *not* authenticate server
+#
+# Subcase 1.A - Message broker configuration does *not* require client authentication
+#
+# - Expect connection success
+# - Expect a verify result of 20 becuase the client did not authenticate the
+# server's certificate.
+#
+# Subcase 1.B - Message broker configuration *does* require client authentication
+#
+# - Expect connection failure (broker must be sent a valid client certificate)
#
+ssl_opts = Stomp::SSLParams.new
hash = { :hosts => [
- {:login => 'guest', :passcode => 'guest', :host => 'localhost', :port => 61612, :ssl => true},
- ]
+ {:login => 'guest', :passcode => 'guest', :host => 'localhost', :port => 61612, :ssl => ssl_opts},
+ ],
+ :reliable => false, # YMMV, to test this in a sane manner
}
#
puts "Connect starts, SSL Use Case 1"
c = Stomp::Connection.new(hash)
puts "Connect completed"
+puts "SSL Verify Result: #{ssl_opts.verify_result}"
+# puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
#
c.disconnect
diff --git a/examples/ssl_uc1_ciphers.rb b/examples/ssl_uc1_ciphers.rb
index 6b1ce48..4019ede 100644
--- a/examples/ssl_uc1_ciphers.rb
+++ b/examples/ssl_uc1_ciphers.rb
@@ -1,12 +1,14 @@
+# -*- encoding: utf-8 -*-
+
#
-# Reference: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
require "rubygems"
require "stomp"
#
# If you need your own ciphers list, this is how.
# Stomp's default list will work in many cases. If you need to use this, you
-# will know it because SSL connect's will fail. In that case, determining
+# will know it because SSL connect will fail. In that case, determining
# _what_ should be in the list is your responsibility.
#
ciphers_list = [["DHE-RSA-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["DHE-DSS-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["AES256-SHA", "TLSv1/SSLv3", 256, 256], ["EDH-RSA-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["EDH-DSS-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DHE-RSA-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["DHE-DSS-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["AES128-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-MD5", "TLSv1/SSLv3", 128, 128], ["EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56], ["EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56],
@@ -25,6 +27,7 @@ hash = { :hosts => [
puts "Connect starts, SSL Use Case 1"
c = Stomp::Connection.new(hash)
puts "Connect completed"
+puts "SSL Verify Result: #{ssl_opts.verify_result}"
#
c.disconnect
diff --git a/examples/ssl_uc2.rb b/examples/ssl_uc2.rb
index 1f516eb..0036502 100644
--- a/examples/ssl_uc2.rb
+++ b/examples/ssl_uc2.rb
@@ -1,30 +1,38 @@
+# -*- encoding: utf-8 -*-
+
#
-# Reference: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
require "rubygems"
require "stomp"
#
-# SSL Use Case 2
+# SSL Use Case 2 - server does *not* authenticate client, client *does* authenticate server
#
-ssl_opts = Stomp::SSLParams.new(:key_file => "/home/gmallard/sslwork/twocas_tj/clientCA/ClientTJ.key",
- :cert_file => "/home/gmallard/sslwork/twocas_tj/clientCA/ClientTJ.crt")
-
+# Subcase 2.A - Message broker configuration does *not* require client authentication
+#
+# - Expect connection success
+# - Expect a verify result of 0 becuase the client did authenticate the
+# server's certificate.
+#
+# Subcase 2.B - Message broker configuration *does* require client authentication
+#
+# - Expect connection failure (broker must be sent a valid client certificate)
+#
+ts_flist = []
+ts_flist << "/home/gmallard/sslwork/twocas_tj/serverCA/ServerTJCA.crt"
+ssl_opts = Stomp::SSLParams.new(:ts_files => ts_flist.join(","))
#
hash = { :hosts => [
{:login => 'guest', :passcode => 'guest', :host => 'localhost', :port => 61612, :ssl => ssl_opts},
- ]
+ ],
+ :reliable => false, # YMMV, to test this in a sane manner
}
#
puts "Connect starts, SSL Use Case 2"
c = Stomp::Connection.new(hash)
puts "Connect completed"
-#
-# Expect a verify_result == 20
-#
-# This means: the client did not verify the peer's certificate, but the
-# handshake succeeds, and the connection is allowed.
-#
puts "SSL Verify Result: #{ssl_opts.verify_result}"
-puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
+# puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
c.disconnect
+
diff --git a/examples/ssl_uc2_ciphers.rb b/examples/ssl_uc2_ciphers.rb
index 49df3bf..f718d1b 100644
--- a/examples/ssl_uc2_ciphers.rb
+++ b/examples/ssl_uc2_ciphers.rb
@@ -1,12 +1,14 @@
+# -*- encoding: utf-8 -*-
+
#
-# Reference: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
require "rubygems"
require "stomp"
#
# If you need your own ciphers list, this is how.
# Stomp's default list will work in many cases. If you need to use this, you
-# will know it because SSL connect's will fail. In that case, determining
+# will know it because SSL connect will fail. In that case, determining
# _what_ should be in the list is your responsibility.
#
ciphers_list = [["DHE-RSA-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["DHE-DSS-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["AES256-SHA", "TLSv1/SSLv3", 256, 256], ["EDH-RSA-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["EDH-DSS-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DHE-RSA-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["DHE-DSS-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["AES128-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-MD5", "TLSv1/SSLv3", 128, 128], ["EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56], ["EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56],
@@ -26,13 +28,7 @@ hash = { :hosts => [
puts "Connect starts, SSL Use Case 2"
c = Stomp::Connection.new(hash)
puts "Connect completed"
-#
-# Expect a verify_result == 20
-#
-# This means: the client did not verify the peer's certificate, but the
-# handshake succeeds, and the connection is allowed.
-#
puts "SSL Verify Result: #{ssl_opts.verify_result}"
-puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
+# puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
c.disconnect
diff --git a/examples/ssl_uc3.rb b/examples/ssl_uc3.rb
index 520cbf1..9daa04d 100644
--- a/examples/ssl_uc3.rb
+++ b/examples/ssl_uc3.rb
@@ -1,29 +1,39 @@
+# -*- encoding: utf-8 -*-
+
#
-# Reference: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
require "rubygems"
require "stomp"
#
-# SSL Use Case 3
+# SSL Use Case 3 - server *does* authenticate client, client does *not* authenticate server
+#
+# Subcase 3.A - Message broker configuration does *not* require client authentication
+#
+# - Expect connection success
+# - Expect a verify result of 20 becuase the client did not authenticate the
+# server's certificate.
#
-ts_flist = []
-ts_flist << "/home/gmallard/sslwork/twocas_tj/serverCA/ServerTJCA.crt"
-ssl_opts = Stomp::SSLParams.new(:ts_files => ts_flist.join(","))
+# Subcase 3.B - Message broker configuration *does* require client authentication
+#
+# - Expect connection success if the server can authenticate the client certificate
+# - Expect a verify result of 20 because the client did not authenticate the
+# server's certificate.
+#
+ssl_opts = Stomp::SSLParams.new(:key_file => "/home/gmallard/sslwork/twocas_tj/clientCA/ClientTJ.key",
+ :cert_file => "/home/gmallard/sslwork/twocas_tj/clientCA/ClientTJ.crt")
+
#
hash = { :hosts => [
{:login => 'guest', :passcode => 'guest', :host => 'localhost', :port => 61612, :ssl => ssl_opts},
- ]
+ ],
+ :reliable => false, # YMMV, to test this in a sane manner
}
#
puts "Connect starts, SSL Use Case 3"
c = Stomp::Connection.new(hash)
puts "Connect completed"
-#
-# Expect a verify_result == 0
-#
-# This means: the client successfully verified the peer's certificate.
-#
puts "SSL Verify Result: #{ssl_opts.verify_result}"
-puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
+# puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
c.disconnect
diff --git a/examples/ssl_uc3_ciphers.rb b/examples/ssl_uc3_ciphers.rb
index d206fb3..7a50bfd 100644
--- a/examples/ssl_uc3_ciphers.rb
+++ b/examples/ssl_uc3_ciphers.rb
@@ -1,12 +1,14 @@
+# -*- encoding: utf-8 -*-
+
#
-# Reference: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
require "rubygems"
require "stomp"
#
# If you need your own ciphers list, this is how.
# Stomp's default list will work in many cases. If you need to use this, you
-# will know it because SSL connect's will fail. In that case, determining
+# will know it because SSL connect will fail. In that case, determining
# _what_ should be in the list is your responsibility.
#
ciphers_list = [["DHE-RSA-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["DHE-DSS-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["AES256-SHA", "TLSv1/SSLv3", 256, 256], ["EDH-RSA-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["EDH-DSS-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DHE-RSA-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["DHE-DSS-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["AES128-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-MD5", "TLSv1/SSLv3", 128, 128], ["EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56], ["EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56],
@@ -26,12 +28,7 @@ hash = { :hosts => [
puts "Connect starts, SSL Use Case 3"
c = Stomp::Connection.new(hash)
puts "Connect completed"
-#
-# Expect a verify_result == 0
-#
-# This means: the client successfully verified the peer's certificate.
-#
puts "SSL Verify Result: #{ssl_opts.verify_result}"
-puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
+# puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
c.disconnect
diff --git a/examples/ssl_uc4.rb b/examples/ssl_uc4.rb
index 970aae2..8668766 100644
--- a/examples/ssl_uc4.rb
+++ b/examples/ssl_uc4.rb
@@ -1,10 +1,24 @@
+# -*- encoding: utf-8 -*-
+
#
-# Reference: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
require "rubygems"
require "stomp"
#
-# SSL Use Case 4
+# SSL Use Case 4 - server *does* authenticate client, client *does* authenticate server
+#
+# Subcase 4.A - Message broker configuration does *not* require client authentication
+#
+# - Expect connection success
+# - Expect a verify result of 0 becuase the client did authenticate the
+# server's certificate.
+#
+# Subcase 4.B - Message broker configuration *does* require client authentication
+#
+# - Expect connection success if the server can authenticate the client certificate
+# - Expect a verify result of 0 because the client did authenticate the
+# server's certificate.
#
ssl_opts = Stomp::SSLParams.new(:key_file => "/home/gmallard/sslwork/twocas_tj/clientCA/ClientTJ.key",
:cert_file => "/home/gmallard/sslwork/twocas_tj/clientCA/ClientTJ.crt",
@@ -12,18 +26,14 @@ ssl_opts = Stomp::SSLParams.new(:key_file => "/home/gmallard/sslwork/twocas_tj/c
#
hash = { :hosts => [
{:login => 'guest', :passcode => 'guest', :host => 'localhost', :port => 61612, :ssl => ssl_opts},
- ]
+ ],
+ :reliable => false, # YMMV, to test this in a sane manner
}
#
puts "Connect starts, SSL Use Case 4"
c = Stomp::Connection.new(hash)
puts "Connect completed"
-#
-# Expect a verify_result == 0
-#
-# This means: the client successfully verified the peer's certificate.
-#
puts "SSL Verify Result: #{ssl_opts.verify_result}"
-puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
+# puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
c.disconnect
diff --git a/examples/ssl_uc4_ciphers.rb b/examples/ssl_uc4_ciphers.rb
index 7b05d0a..f5112e2 100644
--- a/examples/ssl_uc4_ciphers.rb
+++ b/examples/ssl_uc4_ciphers.rb
@@ -1,12 +1,14 @@
+# -*- encoding: utf-8 -*-
+
#
-# Reference: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
require "rubygems"
require "stomp"
#
# If you need your own ciphers list, this is how.
# Stomp's default list will work in many cases. If you need to use this, you
-# will know it because SSL connect's will fail. In that case, determining
+# will know it because SSL connect will fail. In that case, determining
# _what_ should be in the list is your responsibility.
#
ciphers_list = [["DHE-RSA-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["DHE-DSS-AES256-SHA", "TLSv1/SSLv3", 256, 256], ["AES256-SHA", "TLSv1/SSLv3", 256, 256], ["EDH-RSA-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["EDH-DSS-DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DES-CBC3-SHA", "TLSv1/SSLv3", 168, 168], ["DHE-RSA-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["DHE-DSS-AES128-SHA", "TLSv1/SSLv3", 128, 128], ["AES128-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-SHA", "TLSv1/SSLv3", 128, 128], ["RC4-MD5", "TLSv1/SSLv3", 128, 128], ["EDH-RSA-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56], ["EDH-DSS-DES-CBC-SHA", "TLSv1/SSLv3", 56, 56],
@@ -27,12 +29,7 @@ hash = { :hosts => [
puts "Connect starts, SSL Use Case 4"
c = Stomp::Connection.new(hash)
puts "Connect completed"
-#
-# Expect a verify_result == 0
-#
-# This means: the client successfully verified the peer's certificate.
-#
puts "SSL Verify Result: #{ssl_opts.verify_result}"
-puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
+# puts "SSL Peer Certificate:\n#{ssl_opts.peer_cert}"
c.disconnect
diff --git a/examples/ssl_ucx_default_ciphers.rb b/examples/ssl_ucx_default_ciphers.rb
index bc9686c..ad2c8d5 100644
--- a/examples/ssl_ucx_default_ciphers.rb
+++ b/examples/ssl_ucx_default_ciphers.rb
@@ -1,13 +1,16 @@
+# -*- encoding: utf-8 -*-
+
#
-# Reference: https://github.com/morellon/stomp/wiki/extended-ssl-overview
+# Reference: https://github.com/stompgem/stomp/wiki/extended-ssl-overview
#
require "rubygems"
require "stomp"
-
#
-# If you use SSLParams, and need the _default_ Ruby ciphers, this is how.
+# If you use SSLParams, and need the _default_ Ruby ciphers, this is how.
+#
+# NOTE: JRuby users may find that this is a *required* action. YMMV.
#
-ssl_opts = Stomp::SSLParams.new(:use_ruby_ciphers => true)
+ssl_opts = Stomp::SSLParams.new(:use_ruby_ciphers => true) # Plus other parameters as needed
#
# SSL Use Case: Using default Stomp ciphers
#
@@ -17,7 +20,7 @@ hash = { :hosts => [
]
}
#
-puts "Connect starts, SSL Use Case X"
+puts "Connect starts, SSL , Use Default Ruby Ciphers"
c = Stomp::Connection.new(hash)
puts "Connect completed"
#
diff --git a/examples/stomp11_common.rb b/examples/stomp11_common.rb
index aa65bf2..3625802 100644
--- a/examples/stomp11_common.rb
+++ b/examples/stomp11_common.rb
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
#
# Common Stomp 1.1 code.
#
diff --git a/lib/stomp/client.rb b/lib/stomp/client.rb
index b1a09d2..e46eea7 100644
--- a/lib/stomp/client.rb
+++ b/lib/stomp/client.rb
@@ -35,7 +35,7 @@ module Stomp
# stomp://login:passcode@host:port
# stomp://login:passcode@host.domain.tld:port
#
- def initialize(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false)
+ def initialize(login = '', passcode = '', host = 'localhost', port = 61613, reliable = false, autoflush = false)
# Parse stomp:// URL's or set params
if login.is_a?(Hash)
@@ -49,7 +49,6 @@ module Stomp
@port = first_host[:port] || Connection::default_port(first_host[:ssl])
@reliable = true
-
elsif login =~ /^stomp:\/\/#{url_regex}/ # e.g. stomp://login:passcode@host:port or stomp://host:port
@login = $2 || ""
@passcode = $3 || ""
@@ -94,6 +93,7 @@ module Stomp
@connection = Connection.new(@parameters)
else
@connection = Connection.new(@login, @passcode, @host, @port, @reliable)
+ @connection.autoflush = autoflush
end
start_listeners
@@ -265,6 +265,40 @@ module Stomp
@connection.uuid()
end
+ # Retrieve heartbeat send interval
+ def hbsend_interval
+ @connection.hbsend_interval
+ end
+
+ # Retrieve heartbeat receive interval
+ def hbrecv_interval
+ @connection.hbrecv_interval
+ end
+
+ # Retrieve heartbeat send count
+ def hbsend_count
+ @connection.hbsend_count
+ end
+
+ # Retrieve heartbeat receive count
+ def hbrecv_count
+ @connection.hbrecv_count
+ end
+
+ # Poll for asynchronous messages issued by broker.
+ # Return nil of no message available, else the message
+ def poll
+ @connection.poll
+ end
+
+ def autoflush=(af)
+ @connection.autoflush = af
+ end
+
+ def autoflush
+ @connection.autoflush
+ end
+
private
# Set a subscription id in the headers hash if one does not already exist.
# For simplicities sake, all subscriptions have a subscription ID.
diff --git a/lib/stomp/connection.rb b/lib/stomp/connection.rb
index adf59b2..5f2f106 100644
--- a/lib/stomp/connection.rb
+++ b/lib/stomp/connection.rb
@@ -10,12 +10,13 @@ module Stomp
# Low level connection which maps commands and supports
# synchronous receives
class Connection
- attr_reader :connection_frame
- attr_reader :disconnect_receipt
- attr_reader :protocol
- attr_reader :session
- attr_reader :hb_received # Heartbeat received on time
- attr_reader :hb_sent # Heartbeat sent successfully
+ attr_reader :connection_frame
+ attr_reader :disconnect_receipt
+ attr_reader :protocol
+ attr_reader :session
+ attr_reader :hb_received # Heartbeat received on time
+ attr_reader :hb_sent # Heartbeat sent successfully
+ attr_accessor :autoflush
#alias :obj_send :send
def self.default_port(ssl)
@@ -87,6 +88,7 @@ module Stomp
@parse_timeout = 5 # To override, use hashed parameters
@connect_timeout = 0 # To override, use hashed parameters
@logger = nil # To override, use hashed parameters
+ @autoflush = false # To override, use hashed parameters or setter
warn "login looks like a URL, do you have the correct parameters?" if @login =~ /:\/\//
end
@@ -112,6 +114,7 @@ module Stomp
@parse_timeout = @parameters[:parse_timeout]
@connect_timeout = @parameters[:connect_timeout]
@logger = @parameters[:logger]
+ @autoflush = @parameters[:autoflush]
#sets the first host to connect
change_host
end
@@ -170,7 +173,6 @@ module Stomp
def refine_params(params)
params = params.uncamelize_and_symbolize_keys
-
default_params = {
:connect_headers => {},
:reliable => true,
@@ -184,11 +186,15 @@ module Stomp
:backup => false,
:connect_timeout => 0,
# Parse Timeout
- :parse_timeout => 5
+ :parse_timeout => 5,
+ :dmh => false,
}
- default_params.merge(params)
-
+ res_params = default_params.merge(params)
+ if res_params[:dmh]
+ res_params = _expand_hosts(res_params)
+ end
+ return res_params
end
def change_host
@@ -485,11 +491,69 @@ module Stomp
rs
end
+ # Retrieve heartbeat send interval
+ def hbsend_interval
+ return 0 unless @hbsend_interval
+ @hbsend_interval / 1000.0 # ms
+ end
+
+ # Retrieve heartbeat receive interval
+ def hbrecv_interval
+ return 0 unless @hbrecv_interval
+ @hbrecv_interval / 1000.0 # ms
+ end
+
+ # Retrieve heartbeat send count
+ def hbsend_count
+ return 0 unless @hbsend_count
+ @hbsend_count
+ end
+
+ # Retrieve heartbeat receive count
+ def hbrecv_count
+ return 0 unless @hbrecv_count
+ @hbrecv_count
+ end
+
private
+ def _expand_hosts(hash)
+ new_hash = hash.clone
+ new_hash[:hosts_cloned] = hash[:hosts].clone
+ new_hash[:hosts] = []
+ #
+ hash[:hosts].each do |host_parms|
+ ai = Socket.getaddrinfo(host_parms[:host], nil, nil, Socket::SOCK_STREAM)
+ next if ai.nil? || ai.size == 0
+ info6 = ai.detect {|info| info[4] == Socket::AF_INET6}
+ info4 = ai.detect {|info| info[4] == Socket::AF_INET}
+ if info6
+ new_hostp = host_parms.clone
+ new_hostp[:host] = info6[3]
+ new_hash[:hosts] << new_hostp
+ end
+ if info4
+ new_hostp = host_parms.clone
+ new_hostp[:host] = info4[3]
+ new_hash[:hosts] << new_hostp
+ end
+ end
+ return new_hash
+ end
+
def _receive( read_socket )
@read_semaphore.synchronize do
- line = read_socket.gets
+ line = ''
+ if @protocol == Stomp::SPL_10 || (@protocol >= Stomp::SPL_11 && !@hbr)
+ line = read_socket.gets # The old way
+ else # We are >= 1.1 and receiving heartbeats.
+ while true
+ line = read_socket.gets # Data from wire
+ break unless line == "\n"
+ line = ''
+ @lr = Time.now.to_f
+ end
+ end
return nil if line.nil?
# If the reading hangs for more than X seconds, abort the parsing process.
# X defaults to 5. Override allowed in connection hash parameters.
@@ -596,8 +660,8 @@ module Stomp
# and ActiveMQ will interpret the message as a TextMessage.
# For more information refer to http://juretta.com/log/2009/05/24/activemq-jms-stomp/
# Lets send this header in the message, so it can maintain state when using unreceive
- headers['content-length'] = "#{body_length_bytes}" unless headers[:suppress_content_length]
- headers['content-type'] = "text/plain; charset=UTF-8" unless headers['content-type']
+ headers[:'content-length'] = "#{body_length_bytes}" unless headers[:suppress_content_length]
+ headers[:'content-type'] = "text/plain; charset=UTF-8" unless headers[:'content-type']
used_socket.puts command
headers.each do |k,v|
if v.is_a?(Array)
@@ -611,6 +675,7 @@ module Stomp
used_socket.puts
used_socket.write body
used_socket.write "\0"
+ used_socket.flush if autoflush
if @protocol >= Stomp::SPL_11
@ls = Time.now.to_f if @hbs
@@ -684,10 +749,10 @@ module Stomp
if @ssl.cert_file # Any check will do here
raise Stomp::Error::SSLNoCertFileError if !File::exists?(@ssl.cert_file)
raise Stomp::Error::SSLUnreadableCertFileError if !File::readable?(@ssl.cert_file)
- ctx.cert = OpenSSL::X509::Certificate.new(File.open(@ssl.cert_file))
+ ctx.cert = OpenSSL::X509::Certificate.new(File.read(@ssl.cert_file))
raise Stomp::Error::SSLNoKeyFileError if !File::exists?(@ssl.key_file)
raise Stomp::Error::SSLUnreadableKeyFileError if !File::readable?(@ssl.key_file)
- ctx.key = OpenSSL::PKey::RSA.new(File.open(@ssl.key_file))
+ ctx.key = OpenSSL::PKey::RSA.new(File.read(@ssl.key_file), @ssl.key_password)
end
# Cipher list
@@ -815,10 +880,16 @@ module Stomp
def _post_connect
return unless (@connect_headers[:"accept-version"] && @connect_headers[:host])
return if @connection_frame.command == Stomp::CMD_ERROR
+ # We are CONNECTed
cfh = @connection_frame.headers.symbolize_keys
@protocol = cfh[:version]
- # Should not happen, but check anyway
- raise Stomp::Error::UnsupportedProtocolError unless Stomp::SUPPORTED.index(@protocol)
+ if @protocol
+ # Should not happen, but check anyway
+ raise Stomp::Error::UnsupportedProtocolError unless Stomp::SUPPORTED.index(@protocol)
+ else # CONNECTed to a 1.0 server that does not return *any* 1.1 type headers
+ @protocol = Stomp::SPL_10 # reset
+ return
+ end
# Heartbeats
return unless @connect_headers[:"heart-beat"]
_init_heartbeats()
@@ -837,7 +908,9 @@ module Stomp
#
@cx = @cy = @sx = @sy = 0, # Variable names as in spec
#
- @sti = @rti = 0.0 # Send/Receive ticker interval.
+ @hbsend_interval = @hbrecv_interval = 0.0 # Send/Receive ticker interval.
+ #
+ @hbsend_count = @hbrecv_count = 0 # Send/Receive ticker counts.
#
@ls = @lr = -1.0 # Last send/receive time (from Time.now.to_f)
#
@@ -866,7 +939,7 @@ module Stomp
# If sending
if @hbs
sm = @cx >= @sy ? @cx : @sy # ticker interval, ms
- @sti = 1000.0 * sm # ticker interval, μs
+ @hbsend_interval = 1000.0 * sm # ticker interval, μs
@ls = Time.now.to_f # best guess at start
_start_send_ticker
end
@@ -874,7 +947,7 @@ module Stomp
# If receiving
if @hbr
rm = @sx >= @cy ? @sx : @cy # ticker interval, ms
- @rti = 1000.0 * rm # ticker interval, μs
+ @hbrecv_interval = 1000.0 * rm # ticker interval, μs
@lr = Time.now.to_f # best guess at start
_start_receive_ticker
end
@@ -882,7 +955,7 @@ module Stomp
end
def _start_send_ticker
- sleeptime = @sti / 1000000.0 # Sleep time secs
+ sleeptime = @hbsend_interval / 1000000.0 # Sleep time secs
@st = Thread.new {
while true do
sleep sleeptime
@@ -891,7 +964,7 @@ module Stomp
@logger.on_hbfire(log_params, "send_fire", curt)
end
delta = curt - @ls
- if delta > (@sti - (@sti/5.0)) / 1000000.0 # Be tolerant (minus)
+ if delta > (@hbsend_interval - (@hbsend_interval/5.0)) / 1000000.0 # Be tolerant (minus)
if @logger && @logger.respond_to?(:on_hbfire)
@logger.on_hbfire(log_params, "send_heartbeat", curt)
end
@@ -901,10 +974,11 @@ module Stomp
@socket.puts
@ls = curt # Update last send
@hb_sent = true # Reset if necessary
+ @hbsend_count += 1
rescue Exception => sendex
@hb_sent = false # Set the warning flag
if @logger && @logger.respond_to?(:on_hbwrite_fail)
- @logger.on_hbwrite_fail(log_params, {"ticker_interval" => @sti,
+ @logger.on_hbwrite_fail(log_params, {"ticker_interval" => @hbsend_interval,
"exception" => sendex})
end
raise # Re-raise. What else could be done here?
@@ -917,7 +991,7 @@ module Stomp
end
def _start_receive_ticker
- sleeptime = @rti / 1000000.0 # Sleep time secs
+ sleeptime = @hbrecv_interval / 1000000.0 # Sleep time secs
@rt = Thread.new {
while true do
sleep sleeptime
@@ -926,7 +1000,7 @@ module Stomp
@logger.on_hbfire(log_params, "receive_fire", curt)
end
delta = curt - @lr
- if delta > ((@rti + (@rti/5.0)) / 1000000.0) # Be tolerant (plus)
+ if delta > ((@hbrecv_interval + (@hbrecv_interval/5.0)) / 1000000.0) # Be tolerant (plus)
if @logger && @logger.respond_to?(:on_hbfire)
@logger.on_hbfire(log_params, "receive_heartbeat", curt)
end
@@ -942,11 +1016,12 @@ module Stomp
@socket.ungetc(last_char)
end
@read_semaphore.unlock
+ @hbrecv_count += 1
else
# Shrug. Have not received one. Just set warning flag.
@hb_received = false
if @logger && @logger.respond_to?(:on_hbread_fail)
- @logger.on_hbread_fail(log_params, {"ticker_interval" => @rti})
+ @logger.on_hbread_fail(log_params, {"ticker_interval" => @hbrecv_interval})
end
end
else
diff --git a/lib/stomp/message.rb b/lib/stomp/message.rb
index 6d1669d..8cbf112 100644
--- a/lib/stomp/message.rb
+++ b/lib/stomp/message.rb
@@ -41,7 +41,7 @@ module Stomp
end
self.command = work_command
work_headers.split("\n").map do |value|
- parsed_value = value.match /^([\w|-]*):(.*)$/
+ parsed_value = value.match /^([\r|\w|-]*):(.*)$/
raise Stomp::Error::InvalidFormat, 'parsed header value' unless parsed_value
#
pk = parsed_value[1]
diff --git a/lib/stomp/sslparams.rb b/lib/stomp/sslparams.rb
index 40cded9..93600e1 100644
--- a/lib/stomp/sslparams.rb
+++ b/lib/stomp/sslparams.rb
@@ -14,6 +14,8 @@ module Stomp
attr_accessor :cert_file
# The client private key file.
attr_accessor :key_file
+ # The client private key password.
+ attr_accessor :key_password
# SSL Connect Verify Result. The result of the handshake.
attr_accessor :verify_result
# The certificate of the connection peer (the server), received during
@@ -38,6 +40,7 @@ module Stomp
# Client authentication parameters
@cert_file = opts[:cert_file] # Client cert
@key_file = opts[:key_file] # Client key
+ @key_password = opts[:key_password] # Client key password
#
raise Stomp::Error::SSLClientParamsError if @cert_file.nil? && !@key_file.nil?
raise Stomp::Error::SSLClientParamsError if !@cert_file.nil? && @key_file.nil?
diff --git a/lib/stomp/version.rb b/lib/stomp/version.rb
index ce3b2ff..7d11951 100644
--- a/lib/stomp/version.rb
+++ b/lib/stomp/version.rb
@@ -4,7 +4,7 @@ module Stomp
module Version #:nodoc: all
MAJOR = 1
MINOR = 2
- PATCH = 2
+ PATCH = 4
STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
end
end
diff --git a/metadata.yml b/metadata.yml
index 7f1d4c6..c10b6a0 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,13 +1,13 @@
--- !ruby/object:Gem::Specification
name: stomp
version: !ruby/object:Gem::Version
- hash: 27
+ hash: 23
prerelease: false
segments:
- 1
- 2
- - 2
- version: 1.2.2
+ - 4
+ version: 1.2.4
platform: ruby
authors:
- Brian McCallister
@@ -18,7 +18,7 @@ autorequire:
bindir: bin
cert_chain: []
-date: 2012-03-24 00:00:00 -04:00
+date: 2012-06-25 00:00:00 -04:00
default_executable:
dependencies:
- !ruby/object:Gem::Dependency
@@ -108,7 +108,7 @@ files:
- test/test_ssl.rb
- test/tlogger.rb
has_rdoc: true
-homepage: https://github.com/morellon/stomp
+homepage: https://github.com/stompgem/stomp
licenses: []
post_install_message:
diff --git a/spec/client_spec.rb b/spec/client_spec.rb
index 9b3ebd2..78e7d15 100644
--- a/spec/client_spec.rb
+++ b/spec/client_spec.rb
@@ -7,7 +7,7 @@ require 'client_shared_examples'
describe Stomp::Client do
before(:each) do
- @mock_connection = mock('connection')
+ @mock_connection = mock('connection', :autoflush= => true)
Stomp::Connection.stub!(:new).and_return(@mock_connection)
end
@@ -33,6 +33,23 @@ describe Stomp::Client do
end
+ describe "(autoflush)" do
+ it "should delegate to the connection for accessing the autoflush property" do
+ @mock_connection.should_receive(:autoflush)
+ Stomp::Client.new.autoflush
+ end
+
+ it "should delegate to the connection for setting the autoflush property" do
+ @mock_connection.should_receive(:autoflush=).with(true)
+ Stomp::Client.new.autoflush = true
+ end
+
+ it "should set the autoflush property on the connection when passing in autoflush as a parameter to the Stomp::Client" do
+ @mock_connection.should_receive(:autoflush=).with(true)
+ Stomp::Client.new("login", "password", 'localhost', 61613, false, true)
+ end
+ end
+
describe "(created with invalid params)" do
it "should return ArgumentError if host is nil" do
diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb
index 20ae3a8..ae83e1e 100644
--- a/spec/connection_spec.rb
+++ b/spec/connection_spec.rb
@@ -20,7 +20,8 @@ describe Stomp::Connection do
:backup => false,
:connect_timeout => 0,
:parse_timeout => 5,
- :connect_headers => {}
+ :connect_headers => {},
+ :dmh => false
}
#POG:
@@ -32,10 +33,43 @@ describe Stomp::Connection do
# clone() does a shallow copy, we want a deep one so we can garantee the hosts order
normal_parameters = Marshal::load(Marshal::dump(@parameters))
- @tcp_socket = mock(:tcp_socket, :close => nil, :puts => nil, :write => nil, :setsockopt => nil)
+ @tcp_socket = mock(:tcp_socket, :close => nil, :puts => nil, :write => nil, :setsockopt => nil, :flush => true)
TCPSocket.stub!(:open).and_return @tcp_socket
@connection = Stomp::Connection.new(normal_parameters)
end
+
+ describe "autoflush" do
+ let(:parameter_hash) {
+ {
+ "hosts" => [
+ {:login => "login2", :passcode => "passcode2", :host => "remotehost", :port => 61617, :ssl => false},
+ {:login => "login1", :passcode => "passcode1", :host => "localhost", :port => 61616, :ssl => false}
+ ],
+ "reliable" => true,
+ "initialReconnectDelay" => 0.01,
+ "maxReconnectDelay" => 30.0,
+ "useExponentialBackOff" => true,
+ "backOffMultiplier" => 2,
+ "maxReconnectAttempts" => 0,
+ "randomize" => false,
+ "backup" => false,
+ "connect_timeout" => 0,
+ "parse_timeout" => 5,
+ }
+ }
+
+ it "should call flush on the socket when autoflush is true" do
+ @tcp_socket.should_receive(:flush)
+ @connection = Stomp::Connection.new(parameter_hash.merge("autoflush" => true))
+ @connection.publish "/queue", "message", :suppress_content_length => false
+ end
+
+ it "should not call flush on the socket when autoflush is false" do
+ @tcp_socket.should_not_receive(:flush)
+ @connection = Stomp::Connection.new(parameter_hash)
+ @connection.publish "/queue", "message", :suppress_content_length => false
+ end
+ end
describe "(created using a hash)" do
it "should uncamelize and symbolize the main hash keys" do
@@ -53,7 +87,7 @@ describe Stomp::Connection do
"randomize" => false,
"backup" => false,
"connect_timeout" => 0,
- "parse_timeout" => 5,
+ "parse_timeout" => 5
}
@connection = Stomp::Connection.new(used_hash)
@@ -232,7 +266,7 @@ describe Stomp::Connection do
before(:each) do
ssl_parameters = {:hosts => [{:login => "login2", :passcode => "passcode2", :host => "remotehost", :ssl => true}]}
- @ssl_socket = mock(:ssl_socket, :puts => nil, :write => nil, :setsockopt => nil)
+ @ssl_socket = mock(:ssl_socket, :puts => nil, :write => nil, :setsockopt => nil, :flush => true)
TCPSocket.should_receive(:open).and_return @tcp_socket
OpenSSL::SSL::SSLSocket.should_receive(:new).and_return(@ssl_socket)
@@ -298,7 +332,8 @@ describe Stomp::Connection do
:backup => false,
:connect_timeout => 0,
:parse_timeout => 5,
- :connect_headers => {}
+ :connect_headers => {},
+ :dmh => false,
}
used_hash = {
@@ -330,7 +365,8 @@ describe Stomp::Connection do
:parse_timeout => 20,
:connect_headers => {:lerolero => "ronaldo"},
:dead_letter_queue => "queue/Error",
- :max_redeliveries => 10
+ :max_redeliveries => 10,
+ :dmh => false,
}
@connection = Stomp::Connection.new(used_hash)
diff --git a/stomp.gemspec b/stomp.gemspec
index 0834d2f..cf77594 100644
--- a/stomp.gemspec
+++ b/stomp.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{stomp}
- s.version = "1.2.2"
+ s.version = "1.2.4"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Brian McCallister", "Marius Mathiesen", "Thiago Morello", "Guy M. Allard"]
- s.date = %q{2012-03-24}
+ s.date = %q{2012-06-25}
s.description = %q{Ruby client for the Stomp messaging protocol. Note that this gem is no longer supported on rubyforge.}
s.email = ["brianm at apache.org", "marius at stones.com", "morellon at gmail.com", "allard.guy.m at gmail.com"]
s.executables = ["catstomp", "stompcat"]
@@ -75,7 +75,7 @@ Gem::Specification.new do |s|
"test/test_ssl.rb",
"test/tlogger.rb"
]
- s.homepage = %q{https://github.com/morellon/stomp}
+ s.homepage = %q{https://github.com/stompgem/stomp}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{Ruby client for the Stomp messaging protocol}
diff --git a/test/test_client.rb b/test/test_client.rb
index 0eb1678..71cbbbb 100644
--- a/test/test_client.rb
+++ b/test/test_client.rb
@@ -18,6 +18,12 @@ class TestClient < Test::Unit::TestCase
@client.close if @client.open? # allow tests to close
end
+ def test_poll_async
+ # If the test 'hangs' here, Connection#poll is broken.
+ m = @client.poll
+ assert m.nil?
+ end
+
def test_ack_api_works
@client.publish make_destination, message_text, {:suppress_content_length => true}
@@ -63,7 +69,7 @@ class TestClient < Test::Unit::TestCase
assert_equal message_text, received2.body
assert_equal received.body, received2.body
assert_equal received.headers['message-id'], received2.headers['message-id'] unless ENV['STOMP_RABBIT']
- end
+ end unless RUBY_ENGINE =~ /jruby/
def test_receipts
receipt = false
@@ -98,7 +104,7 @@ class TestClient < Test::Unit::TestCase
assert_raise(RuntimeError) do
@client.subscribe make_destination
end
- end
+ end unless RUBY_ENGINE =~ /jruby/
def test_transactional_publish
@client.begin 'tx1'
@@ -125,7 +131,7 @@ class TestClient < Test::Unit::TestCase
@client.subscribe(make_destination) {|m| message = m}
sleep 0.01 until message
assert_equal "second_message", message.body
- end
+ end unless RUBY_ENGINE =~ /jruby/
def test_transaction_ack_rollback_with_new_client
@client.publish make_destination, message_text
@@ -306,7 +312,7 @@ class TestClient < Test::Unit::TestCase
def test_connection_frame
assert_not_nil @client.connection_frame
- end
+ end unless RUBY_ENGINE =~ /jruby/
def test_unsubscribe
message = nil
@@ -366,7 +372,7 @@ class TestClient < Test::Unit::TestCase
@client.publish(dest, message_text)
sleep 1
assert_not_nil msg
- end
+ end unless RUBY_ENGINE =~ /jruby/
def test_thread_multi_subscribe
#
diff --git a/test/test_connection.rb b/test/test_connection.rb
index e5c4b0d..554ab0a 100644
--- a/test/test_connection.rb
+++ b/test/test_connection.rb
@@ -382,7 +382,37 @@ class TestConnection < Test::Unit::TestCase
msg2 = @conn.receive
assert_equal smsg, msg2.body
end
- end
+ end unless ENV['STOMP_AMQ11'] # AMQ sends NACK'd messages to a DLQ
+ # Test to illustrate Issue #44. Prior to a fix for #44, these tests would
+ # fail only when connecting to a pure STOMP 1.0 server that does not
+ # return a 'version' header at all.
+ def test_conn10_simple
+ @conn.disconnect
+ #
+ hash = { :hosts => [
+ {:login => user, :passcode => passcode, :host => host, :port => port, :ssl => false},
+ ],
+ :connect_headers => {"accept-version" => "1.0", "host" => host},
+ :reliable => false,
+ }
+ c = nil
+ assert_nothing_raised {
+ c = Stomp::Connection.new(hash)
+ }
+ c.disconnect if c
+ #
+ hash = { :hosts => [
+ {:login => user, :passcode => passcode, :host => host, :port => port, :ssl => false},
+ ],
+ :connect_headers => {"accept-version" => "3.14159,1.0,12.0", "host" => host},
+ :reliable => false,
+ }
+ c = nil
+ assert_nothing_raised {
+ c = Stomp::Connection.new(hash)
+ }
+ c.disconnect if c
+ end
end
diff --git a/test/test_connection1p.rb b/test/test_connection1p.rb
index e56123d..edf371e 100644
--- a/test/test_connection1p.rb
+++ b/test/test_connection1p.rb
@@ -102,6 +102,8 @@ class TestConnection1P < Test::Unit::TestCase
conn = Stomp::Connection.open(user, passcode, host, port, false, 5, cha)
conn.disconnect
end
+ assert conn.hbsend_interval > 0
+ assert conn.hbrecv_interval > 0
end
#
@@ -109,7 +111,7 @@ class TestConnection1P < Test::Unit::TestCase
#
cha = {:host => "localhost", "accept-version" => "1.1"}
cha[:host] = "/" if ENV['STOMP_RABBIT']
- cha["heart-beat"] = "5000,0" # Valid heart beat headers, send only
+ cha["heart-beat"] = "10000,0" # Valid heart beat headers, send only
conn = nil
logger = Tlogger.new
assert_nothing_raised do
@@ -119,6 +121,7 @@ class TestConnection1P < Test::Unit::TestCase
conn.set_logger(nil)
conn.disconnect
end
+ hb_asserts_send(conn)
end if ENV['STOMP_HB11LONG']
#
@@ -126,7 +129,7 @@ class TestConnection1P < Test::Unit::TestCase
#
cha = {:host => "localhost", "accept-version" => "1.1"}
cha[:host] = "/" if ENV['STOMP_RABBIT']
- cha["heart-beat"] = "0,10000" # Valid heart beat headers, receive only
+ cha["heart-beat"] = "0,6000" # Valid heart beat headers, receive only
conn = nil
logger = Tlogger.new
assert_nothing_raised do
@@ -137,6 +140,7 @@ class TestConnection1P < Test::Unit::TestCase
conn.set_logger(nil)
conn.disconnect
end
+ hb_asserts_recv(conn)
end if ENV['STOMP_HB11LONG']
#
@@ -155,7 +159,9 @@ class TestConnection1P < Test::Unit::TestCase
conn.set_logger(nil)
conn.disconnect
end
+ hb_asserts_both(conn)
end if ENV['STOMP_HB11LONG']
+
#
def test_conn_1p_0110
#
@@ -255,5 +261,86 @@ class TestConnection1P < Test::Unit::TestCase
@conn.subscribe dest, :id => sid
}
end
+
+ #
+ def test_conn_1p_0130
+ #
+ cha = {:host => "localhost", "accept-version" => "1.1"}
+ cha[:host] = "/" if ENV['STOMP_RABBIT']
+ cha["heart-beat"] = "10000,6000" # Valid heart beat headers, send and receive
+ conn = nil
+ logger = Tlogger.new
+ assert_nothing_raised do
+ conn = Stomp::Connection.open(user, passcode, host, port, false, 5, cha)
+# m = conn.receive # This will hang forever .....
+ conn.set_logger(logger)
+ sleep 65
+ conn.set_logger(nil)
+ conn.disconnect
+ end
+ hb_asserts_both(conn)
+ end if ENV['STOMP_HB11LONG']
+
+ #
+ def test_conn_1p_0130
+ #
+ cha = {:host => "localhost", "accept-version" => "1.1"}
+ cha[:host] = "/" if ENV['STOMP_RABBIT']
+ cha["heart-beat"] = "10000,1000" # Valid heart beat headers, send and receive
+ conn = nil
+ logger = Tlogger.new
+ assert_nothing_raised do
+ conn = Stomp::Connection.open(user, passcode, host, port, false, 5, cha)
+# m = conn.receive # This will hang forever .....
+ conn.set_logger(logger)
+ sleep 65
+ conn.set_logger(nil)
+ conn.disconnect
+ end
+ hb_asserts_both(conn)
+ end if ENV['STOMP_HB11LONG']
+
+ #
+ def test_conn_1p_0140
+ #
+ cha = {:host => "localhost", "accept-version" => "1.1"}
+ cha[:host] = "/" if ENV['STOMP_RABBIT']
+ cha["heart-beat"] = "1000,10000" # Valid heart beat headers, send and receive
+ conn = nil
+ logger = Tlogger.new
+ assert_nothing_raised do
+ conn = Stomp::Connection.open(user, passcode, host, port, false, 5, cha)
+# m = conn.receive # This will hang forever .....
+ conn.set_logger(logger)
+ sleep 65
+ conn.set_logger(nil)
+ conn.disconnect
+ end
+ hb_asserts_both(conn)
+ end if ENV['STOMP_HB11LONG']
+
+private
+
+ def hb_asserts_both(conn)
+ assert conn.hbsend_interval > 0
+ assert conn.hbrecv_interval > 0
+ assert conn.hbsend_count > 0
+ assert conn.hbrecv_count > 0
+ end
+
+ def hb_asserts_send(conn)
+ assert conn.hbsend_interval > 0
+ assert conn.hbrecv_interval == 0
+ assert conn.hbsend_count > 0
+ assert conn.hbrecv_count == 0
+ end
+
+ def hb_asserts_recv(conn)
+ assert conn.hbsend_interval == 0
+ assert conn.hbrecv_interval > 0
+ assert conn.hbsend_count == 0
+ assert conn.hbrecv_count > 0
+ end
+
end if ENV['STOMP_TEST11']
--
ruby-stomp.git
More information about the Pkg-ruby-extras-commits
mailing list