jruby-jms 1.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +8 -0
  3. data/Gemfile.lock +36 -0
  4. data/HISTORY.md +52 -0
  5. data/LICENSE.txt +201 -0
  6. data/README.md +205 -0
  7. data/Rakefile +30 -0
  8. data/examples/advanced/session_pool.rb +37 -0
  9. data/examples/client-server/replier.rb +29 -0
  10. data/examples/client-server/requestor.rb +40 -0
  11. data/examples/file-to-q/files_to_q.rb +51 -0
  12. data/examples/file-to-q/q_to_files.rb +44 -0
  13. data/examples/invm/invm.rb +44 -0
  14. data/examples/invm/log4j.properties +58 -0
  15. data/examples/jms.yml +149 -0
  16. data/examples/performance/consumer.rb +25 -0
  17. data/examples/performance/producer.rb +31 -0
  18. data/examples/producer-consumer/browser.rb +24 -0
  19. data/examples/producer-consumer/consumer.rb +24 -0
  20. data/examples/producer-consumer/consumer_async.rb +41 -0
  21. data/examples/producer-consumer/producer.rb +25 -0
  22. data/examples/publish-subscribe/publish.rb +24 -0
  23. data/examples/publish-subscribe/subscribe.rb +31 -0
  24. data/lib/jms.rb +20 -0
  25. data/lib/jms/bytes_message.rb +52 -0
  26. data/lib/jms/connection.rb +529 -0
  27. data/lib/jms/imports.rb +21 -0
  28. data/lib/jms/logging.rb +50 -0
  29. data/lib/jms/map_message.rb +91 -0
  30. data/lib/jms/message.rb +285 -0
  31. data/lib/jms/message_consumer.rb +117 -0
  32. data/lib/jms/message_listener_impl.rb +79 -0
  33. data/lib/jms/message_producer.rb +59 -0
  34. data/lib/jms/mq_workaround.rb +70 -0
  35. data/lib/jms/object_message.rb +26 -0
  36. data/lib/jms/oracle_a_q_connection_factory.rb +48 -0
  37. data/lib/jms/queue_browser.rb +28 -0
  38. data/lib/jms/session.rb +473 -0
  39. data/lib/jms/session_pool.rb +168 -0
  40. data/lib/jms/text_message.rb +31 -0
  41. data/lib/jms/version.rb +3 -0
  42. data/nbproject/private/private.properties +3 -0
  43. data/nbproject/private/rake-d.txt +5 -0
  44. data/parallel_minion.gemspec +21 -0
  45. data/test/connection_test.rb +160 -0
  46. data/test/jms.yml +111 -0
  47. data/test/log4j.properties +32 -0
  48. data/test/message_test.rb +130 -0
  49. data/test/session_pool_test.rb +86 -0
  50. data/test/session_test.rb +140 -0
  51. metadata +113 -0
@@ -0,0 +1,32 @@
1
+ #
2
+ # This file controls most of the logging in ActiveMQ which is mainly based around
3
+ # the commons logging API.
4
+ #
5
+ log4j.rootLogger=INFO, console
6
+ log4j.logger.org.apache.activemq.spring=WARN
7
+ log4j.logger.org.apache.activemq.web.handler=WARN
8
+ log4j.logger.org.springframework=WARN
9
+ log4j.logger.org.apache.xbean=WARN
10
+ log4j.logger.org.apache.camel=INFO
11
+
12
+ # When debugging or reporting problems to the ActiveMQ team,
13
+ # comment out the above lines and uncomment the next.
14
+
15
+ #log4j.rootLogger=DEBUG, logfile, console
16
+
17
+ # Or for more fine grained debug logging uncomment one of these
18
+ #log4j.logger.org.apache.activemq=DEBUG
19
+ #log4j.logger.org.apache.camel=DEBUG
20
+
21
+ # Console appender
22
+ log4j.appender.console=org.apache.log4j.ConsoleAppender
23
+ log4j.appender.console.layout=org.apache.log4j.PatternLayout
24
+ log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p: %m [%c %t]%n
25
+ log4j.appender.console.threshold=INFO
26
+
27
+ log4j.additivity.org.apache.activemq.audit=false
28
+ log4j.logger.org.apache.activemq.audit=INFO, audit
29
+
30
+ log4j.appender.audit=org.apache.log4j.ConsoleAppender
31
+ log4j.appender.audit.layout=org.apache.log4j.PatternLayout
32
+ log4j.appender.audit.layout.ConversionPattern=%d{ISO8601} %-5p: %m [%c %t]%n
@@ -0,0 +1,130 @@
1
+ # Allow examples to be run in-place without requiring a gem install
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'shoulda'
7
+ require 'jms'
8
+ require 'yaml'
9
+
10
+ class JMSTest < Test::Unit::TestCase
11
+ context 'JMS Session' do
12
+ # Load configuration from jms.yml
13
+ setup do
14
+ # To change the JMS provider, edit jms.yml and change :default
15
+
16
+ # Load Connection parameters from configuration file
17
+ cfg = YAML.load_file(File.join(File.dirname(__FILE__), 'jms.yml'))
18
+ jms_provider = cfg['default']
19
+ @config = cfg[jms_provider]
20
+ raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless @config
21
+ @queue_name = @config.delete(:queue_name) || raise("Mandatory :queue_name missing from jms.yml")
22
+ @topic_name = @config.delete(:topic_name) || raise("Mandatory :topic_name missing from jms.yml")
23
+ end
24
+
25
+ should 'produce and consume messages to/from a temporary queue' do
26
+ JMS::Connection.session(@config) do |session|
27
+ assert_not_nil session
28
+ data = nil
29
+ session.producer(:queue_name => :temporary) do |producer|
30
+ # Send Message
31
+ producer.send(session.message('Hello World'))
32
+
33
+ # Consume Message
34
+ session.consume(:destination => producer.destination, :timeout=>1000) do |message|
35
+ assert_equal message.java_kind_of?(JMS::TextMessage), true
36
+ data = message.data
37
+ end
38
+ end
39
+ assert_equal data, 'Hello World'
40
+ end
41
+ end
42
+
43
+ should 'produce, browse and consume messages to/from a queue' do
44
+ JMS::Connection.session(@config) do |session|
45
+ assert_not_nil session
46
+ data = :timed_out
47
+ browse_data = :timed_out
48
+ session.producer(:queue_name => @queue_name) do |producer|
49
+ # Send Message
50
+ producer.send(session.message('Hello World'))
51
+
52
+ # Browse Message
53
+ session.browse(:queue_name => @queue_name, :timeout=>1000) do |message|
54
+ assert_equal message.java_kind_of?(JMS::TextMessage), true
55
+ browse_data = message.data
56
+ end
57
+
58
+ # Consume Message
59
+ session.consume(:queue_name => @queue_name, :timeout=>1000) do |message|
60
+ assert_equal message.java_kind_of?(JMS::TextMessage), true
61
+ data = message.data
62
+ end
63
+ end
64
+ assert_equal 'Hello World', data
65
+ assert_equal 'Hello World', browse_data
66
+ end
67
+ end
68
+
69
+ should 'support setting persistence using symbols and the java constants' do
70
+ JMS::Connection.session(@config) do |session|
71
+ message = session.message('Hello World')
72
+ message.jms_delivery_mode_sym = :non_persistent
73
+ assert_equal message.jms_delivery_mode_sym, :non_persistent
74
+ message.jms_delivery_mode_sym = :persistent
75
+ assert_equal message.jms_delivery_mode_sym, :persistent
76
+ end
77
+ end
78
+
79
+ should 'produce and consume non-persistent messages' do
80
+ JMS::Connection.session(@config) do |session|
81
+ assert_not_nil session
82
+ data = nil
83
+ session.producer(:queue_name => :temporary) do |producer|
84
+ message = session.message('Hello World')
85
+ message.jms_delivery_mode_sym = :non_persistent
86
+ assert_equal :non_persistent, message.jms_delivery_mode_sym
87
+ assert_equal false, message.persistent?
88
+
89
+ # Send Message
90
+ producer.send(message)
91
+
92
+ # Consume Message
93
+ session.consume(:destination => producer.destination, :timeout=>1000) do |message|
94
+ assert_equal message.java_kind_of?(JMS::TextMessage), true
95
+ data = message.data
96
+ #assert_equal :non_persistent, message.jms_delivery_mode
97
+ #assert_equal false, message.persistent?
98
+ end
99
+ end
100
+ assert_equal data, 'Hello World'
101
+ end
102
+ end
103
+
104
+ should 'produce and consume persistent messages' do
105
+ JMS::Connection.session(@config) do |session|
106
+ assert_not_nil session
107
+ data = nil
108
+ session.producer(:queue_name => @queue_name) do |producer|
109
+ message = session.message('Hello World')
110
+ message.jms_delivery_mode_sym = :persistent
111
+ assert_equal :persistent, message.jms_delivery_mode_sym
112
+ assert_equal true, message.persistent?
113
+
114
+ # Send Message
115
+ producer.send(message)
116
+
117
+ # Consume Message
118
+ session.consume(:destination => producer.destination, :timeout=>1000) do |message|
119
+ assert_equal message.java_kind_of?(JMS::TextMessage), true
120
+ data = message.data
121
+ assert_equal :persistent, message.jms_delivery_mode_sym
122
+ assert_equal true, message.persistent?
123
+ end
124
+ end
125
+ assert_equal data, 'Hello World'
126
+ end
127
+ end
128
+
129
+ end
130
+ end
@@ -0,0 +1,86 @@
1
+ # Allow examples to be run in-place without requiring a gem install
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'shoulda'
7
+ require 'jms'
8
+ require 'yaml'
9
+
10
+ class JMSTest < Test::Unit::TestCase
11
+ context 'JMS Session' do
12
+ # Load configuration from jms.yml
13
+ setup do
14
+ # To change the JMS provider, edit jms.yml and change :default
15
+
16
+ # Load Connection parameters from configuration file
17
+ cfg = YAML.load_file(File.join(File.dirname(__FILE__), 'jms.yml'))
18
+ jms_provider = cfg['default']
19
+ @config = cfg[jms_provider]
20
+ raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless @config
21
+ @queue_name = @config.delete(:queue_name) || raise("Mandatory :queue_name missing from jms.yml")
22
+ @topic_name = @config.delete(:topic_name) || raise("Mandatory :topic_name missing from jms.yml")
23
+ @pool_params = {
24
+ :pool_name => 'Test::JMS::SessionPool',
25
+ :pool_size => 10,
26
+ :pool_warn_timeout => 5.0,
27
+ #:pool_logger =>
28
+ }
29
+ end
30
+
31
+ should 'create a session pool' do
32
+ JMS::Connection.start(@config) do |connection|
33
+ pool = connection.create_session_pool(@pool_params)
34
+ pool.session do |session|
35
+ assert_not_nil session
36
+ assert session.is_a?(javax.jms.Session)
37
+ end
38
+ pool.close
39
+ end
40
+ end
41
+
42
+ should 'remove bad session from pool' do
43
+ JMS::Connection.start(@config) do |connection|
44
+ pool = connection.create_session_pool(@pool_params.merge(:pool_size=>1))
45
+ s = nil
46
+ r = begin
47
+ pool.session do |session|
48
+ assert_not_nil session
49
+ assert session.is_a?(javax.jms.Session)
50
+ s = session
51
+ s.close
52
+ s.create_map_message
53
+ false
54
+ end
55
+ rescue javax.jms.IllegalStateException
56
+ true
57
+ end
58
+ assert r == true
59
+
60
+ # Now verify that the previous closed session was removed from the pool
61
+ pool.session do |session|
62
+ assert_not_nil session
63
+ assert session.is_a?(javax.jms.Session)
64
+ assert s != session
65
+ session.create_map_message
66
+ end
67
+ end
68
+ end
69
+
70
+ should 'allow multiple sessions to be used concurrently' do
71
+ JMS::Connection.start(@config) do |connection|
72
+ pool = connection.create_session_pool(@pool_params)
73
+ pool.session do |session|
74
+ assert_not_nil session
75
+ assert session.is_a?(javax.jms.Session)
76
+ pool.session do |session2|
77
+ assert_not_nil session2
78
+ assert session2.is_a?(javax.jms.Session)
79
+ assert session != session2
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,140 @@
1
+ # Allow examples to be run in-place without requiring a gem install
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'shoulda'
7
+ require 'jms'
8
+ require 'yaml'
9
+
10
+ class JMSTest < Test::Unit::TestCase
11
+ context 'JMS Session' do
12
+ # Load configuration from jms.yml
13
+ setup do
14
+ # To change the JMS provider, edit jms.yml and change :default
15
+
16
+ # Load Connection parameters from configuration file
17
+ cfg = YAML.load_file(File.join(File.dirname(__FILE__), 'jms.yml'))
18
+ jms_provider = cfg['default']
19
+ @config = cfg[jms_provider]
20
+ raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless @config
21
+ @queue_name = @config.delete(:queue_name) || raise("Mandatory :queue_name missing from jms.yml")
22
+ @topic_name = @config.delete(:topic_name) || raise("Mandatory :topic_name missing from jms.yml")
23
+ end
24
+
25
+ should 'create a session' do
26
+ JMS::Connection.session(@config) do |session|
27
+ assert_not_nil session
28
+ end
29
+ end
30
+
31
+ should 'create automatic messages' do
32
+ JMS::Connection.session(@config) do |session|
33
+ assert_not_nil session
34
+ # Create Text Message
35
+ assert_equal session.message("Hello").java_kind_of?(JMS::TextMessage), true
36
+
37
+ # Create Map Message
38
+ assert_equal session.message('hello'=>'world').java_kind_of?(JMS::MapMessage), true
39
+ end
40
+ end
41
+
42
+ should 'create explicit messages' do
43
+ JMS::Connection.session(@config) do |session|
44
+ assert_not_nil session
45
+ # Create Text Message
46
+ assert_equal session.create_text_message("Hello").java_kind_of?(JMS::TextMessage), true
47
+
48
+ # Create Map Message
49
+ assert_equal session.create_map_message.java_kind_of?(JMS::MapMessage), true
50
+ end
51
+ end
52
+
53
+ should 'create temporary destinations in blocks' do
54
+ JMS::Connection.session(@config) do |session|
55
+ assert_not_nil session
56
+
57
+ # Temporary Queue
58
+ session.destination(:queue_name => :temporary) do |destination|
59
+ assert_equal destination.java_kind_of?(JMS::TemporaryQueue), true
60
+ end
61
+
62
+ # Temporary Topic
63
+ session.create_destination(:topic_name => :temporary) do |destination|
64
+ assert_equal destination.java_kind_of?(JMS::TemporaryTopic), true
65
+ end
66
+ end
67
+ end
68
+
69
+ should 'create temporary destinations' do
70
+ JMS::Connection.session(@config) do |session|
71
+ assert_not_nil session
72
+
73
+ # Temporary Queue
74
+ destination = session.create_destination(:queue_name => :temporary)
75
+ assert_equal destination.java_kind_of?(JMS::TemporaryQueue), true
76
+ destination.delete
77
+
78
+ # Temporary Topic
79
+ destination = session.create_destination(:topic_name => :temporary)
80
+ assert_equal destination.java_kind_of?(JMS::TemporaryTopic), true
81
+ destination.delete
82
+ end
83
+ end
84
+
85
+ should 'create destinations in blocks' do
86
+ JMS::Connection.session(@config) do |session|
87
+ assert_not_nil session
88
+
89
+ # Temporary Queue
90
+ session.destination(:queue_name => @queue_name) do |destination|
91
+ assert_equal destination.java_kind_of?(JMS::Queue), true
92
+ end
93
+
94
+ # Temporary Topic
95
+ session.create_destination(:topic_name => @topic_name) do |destination|
96
+ assert_equal destination.java_kind_of?(JMS::Topic), true
97
+ end
98
+ end
99
+ end
100
+
101
+ should 'create destinations' do
102
+ JMS::Connection.session(@config) do |session|
103
+ assert_not_nil session
104
+
105
+ # Queue
106
+ queue = session.create_destination(:queue_name => @queue_name)
107
+ assert_equal queue.java_kind_of?(JMS::Queue), true
108
+
109
+ # Topic
110
+ topic = session.create_destination(:topic_name => @topic_name)
111
+ assert_equal topic.java_kind_of?(JMS::Topic), true
112
+ end
113
+ end
114
+
115
+ should 'create destinations using direct methods' do
116
+ JMS::Connection.session(@config) do |session|
117
+ assert_not_nil session
118
+
119
+ # Queue
120
+ queue = session.queue(@queue_name)
121
+ assert_equal queue.java_kind_of?(JMS::Queue), true
122
+
123
+ # Temporary Queue
124
+ queue = session.temporary_queue
125
+ assert_equal queue.java_kind_of?(JMS::TemporaryQueue), true
126
+ queue.delete
127
+
128
+ # Topic
129
+ topic = session.topic(@topic_name)
130
+ assert_equal topic.java_kind_of?(JMS::Topic), true
131
+
132
+ # Temporary Topic
133
+ topic = session.temporary_topic
134
+ assert_equal topic.java_kind_of?(JMS::TemporaryTopic), true
135
+ topic.delete
136
+ end
137
+ end
138
+
139
+ end
140
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jruby-jms
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: java
6
+ authors:
7
+ - Reid Morrison
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gene_pool
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :runtime
27
+ description: JRuby-JMS is a Java and Ruby library that exposes the Java JMS API in a ruby friendly way. For JRuby only.
28
+ email:
29
+ - reidmo@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - HISTORY.md
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - examples/advanced/session_pool.rb
41
+ - examples/client-server/replier.rb
42
+ - examples/client-server/requestor.rb
43
+ - examples/file-to-q/files_to_q.rb
44
+ - examples/file-to-q/q_to_files.rb
45
+ - examples/invm/invm.rb
46
+ - examples/invm/log4j.properties
47
+ - examples/jms.yml
48
+ - examples/performance/consumer.rb
49
+ - examples/performance/producer.rb
50
+ - examples/producer-consumer/browser.rb
51
+ - examples/producer-consumer/consumer.rb
52
+ - examples/producer-consumer/consumer_async.rb
53
+ - examples/producer-consumer/producer.rb
54
+ - examples/publish-subscribe/publish.rb
55
+ - examples/publish-subscribe/subscribe.rb
56
+ - lib/jms.rb
57
+ - lib/jms/bytes_message.rb
58
+ - lib/jms/connection.rb
59
+ - lib/jms/imports.rb
60
+ - lib/jms/logging.rb
61
+ - lib/jms/map_message.rb
62
+ - lib/jms/message.rb
63
+ - lib/jms/message_consumer.rb
64
+ - lib/jms/message_listener_impl.rb
65
+ - lib/jms/message_producer.rb
66
+ - lib/jms/mq_workaround.rb
67
+ - lib/jms/object_message.rb
68
+ - lib/jms/oracle_a_q_connection_factory.rb
69
+ - lib/jms/queue_browser.rb
70
+ - lib/jms/session.rb
71
+ - lib/jms/session_pool.rb
72
+ - lib/jms/text_message.rb
73
+ - lib/jms/version.rb
74
+ - nbproject/private/private.properties
75
+ - nbproject/private/rake-d.txt
76
+ - parallel_minion.gemspec
77
+ - test/connection_test.rb
78
+ - test/jms.yml
79
+ - test/log4j.properties
80
+ - test/message_test.rb
81
+ - test/session_pool_test.rb
82
+ - test/session_test.rb
83
+ homepage: https://github.com/reidmorrison/jruby-jms
84
+ licenses:
85
+ - Apache License V2.0
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: JRuby interface into JMS
107
+ test_files:
108
+ - test/connection_test.rb
109
+ - test/jms.yml
110
+ - test/log4j.properties
111
+ - test/message_test.rb
112
+ - test/session_pool_test.rb
113
+ - test/session_test.rb