jruby-jms 1.1.0-java → 1.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +24 -7
  3. data/README.md +49 -49
  4. data/Rakefile +17 -12
  5. data/lib/jms.rb +8 -17
  6. data/lib/jms/bytes_message.rb +3 -19
  7. data/lib/jms/connection.rb +63 -83
  8. data/lib/jms/map_message.rb +9 -25
  9. data/lib/jms/message.rb +22 -173
  10. data/lib/jms/message_consumer.rb +23 -35
  11. data/lib/jms/message_listener_impl.rb +22 -38
  12. data/lib/jms/message_producer.rb +9 -25
  13. data/lib/jms/mq_workaround.rb +11 -26
  14. data/lib/jms/object_message.rb +1 -17
  15. data/lib/jms/oracle_a_q_connection_factory.rb +4 -21
  16. data/lib/jms/queue_browser.rb +2 -18
  17. data/lib/jms/session.rb +92 -106
  18. data/lib/jms/session_pool.rb +34 -41
  19. data/lib/jms/text_message.rb +0 -16
  20. data/lib/jms/version.rb +1 -1
  21. data/test/connection_test.rb +35 -81
  22. data/test/jms.yml +18 -8
  23. data/test/message_test.rb +27 -43
  24. data/test/session_pool_test.rb +30 -46
  25. data/test/session_test.rb +30 -45
  26. data/test/test_helper.rb +33 -0
  27. metadata +20 -26
  28. data/Gemfile +0 -8
  29. data/Gemfile.lock +0 -36
  30. data/examples/advanced/session_pool.rb +0 -37
  31. data/examples/client-server/replier.rb +0 -29
  32. data/examples/client-server/requestor.rb +0 -40
  33. data/examples/file-to-q/files_to_q.rb +0 -51
  34. data/examples/file-to-q/q_to_files.rb +0 -44
  35. data/examples/invm/invm.rb +0 -44
  36. data/examples/invm/log4j.properties +0 -58
  37. data/examples/jms.yml +0 -149
  38. data/examples/performance/consumer.rb +0 -25
  39. data/examples/performance/producer.rb +0 -31
  40. data/examples/producer-consumer/browser.rb +0 -24
  41. data/examples/producer-consumer/consumer.rb +0 -24
  42. data/examples/producer-consumer/consumer_async.rb +0 -41
  43. data/examples/producer-consumer/producer.rb +0 -25
  44. data/examples/publish-subscribe/publish.rb +0 -24
  45. data/examples/publish-subscribe/subscribe.rb +0 -31
  46. data/lib/jms/logging.rb +0 -50
  47. data/nbproject/private/private.properties +0 -3
  48. data/nbproject/private/rake-d.txt +0 -5
  49. data/parallel_minion.gemspec +0 -21
@@ -1,37 +0,0 @@
1
- #
2
- # How to use the session pool in a multi-threaded application such as Rails
3
- # This example shows how to have multiple producers publishing information
4
- # to topics
5
- #
6
-
7
- # Allow examples to be run in-place without requiring a gem install
8
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
9
-
10
- require 'rubygems'
11
- require 'yaml'
12
- require 'jms'
13
-
14
- jms_provider = ARGV[0] || 'activemq'
15
-
16
- ### This part would typically go in a Rails Initializer ###
17
-
18
- # Load Connection parameters from configuration file
19
- config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'jms.yml'))[jms_provider]
20
- raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless config
21
-
22
- JMS_CONNECTION = JMS::Connection.new(config)
23
- JMS_CONNECTION.start
24
- JMS_SESSION_POOL = JMS_CONNECTION.create_session_pool(config)
25
-
26
- # Ensure connections are released if application is shutdown
27
- at_exit do
28
- JMS_SESSION_POOL.close
29
- JMS_CONNECTION.close
30
- end
31
-
32
- ### This part would typically go in the Rails Model ###
33
-
34
- JMS_SESSION_POOL.producer(:queue_name => 'SampleQueue') do |session, producer|
35
- producer.send(session.message("Hello World"))
36
- end
37
-
@@ -1,29 +0,0 @@
1
- #
2
- # Sample request/reply pattern replier:
3
- # Basically does the following:
4
- # 1) Consume messages from ExampleQueue indefinitely
5
- # 2) Get JMSReplyTo from consumed message
6
- # 3) Produce and send response to received message
7
- #
8
-
9
- # Allow examples to be run in-place without requiring a gem install
10
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
11
-
12
- require 'rubygems'
13
- require 'jms'
14
- require 'yaml'
15
-
16
- jms_provider = ARGV[0] || 'activemq'
17
-
18
- # Load Connection parameters from configuration file
19
- config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'jms.yml'))[jms_provider]
20
- raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless config
21
-
22
- JMS::Connection.session(config) do |session|
23
- session.consume(:queue_name => "ExampleQueue", :timeout => -1) do |message|
24
- p "Got message: #{message.data}. Replying politely."
25
- session.producer(:destination => message.reply_to) do |producer|
26
- producer.send(session.message("Hello to you too!"))
27
- end
28
- end
29
- end
@@ -1,40 +0,0 @@
1
- #
2
- # Sample request/reply pattern requestor implementation:
3
- # Basically what this does is:
4
- # 1) Create temporary Queue to MQ Session
5
- # 2) Create consumer to session (This is important to be up before producer to make sure response isn't available before consumer is up)
6
- # 3) Create producer to session
7
- # 4) Create message for session
8
- # 5) Set message's JMSReplyTo to point to the temporary queue created in #1
9
- # 6) Send message to send queue
10
- # 7) Consume the first message available from the temporary queue within the time set in :timeout
11
- # 8) Close temporary queue, consumer, producer and session by ending the blocks
12
- #
13
-
14
- # Allow examples to be run in-place without requiring a gem install
15
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
16
-
17
- require 'rubygems'
18
- require 'yaml'
19
- require 'jms'
20
-
21
- jms_provider = ARGV[0] || 'activemq'
22
-
23
- # Load Connection parameters from configuration file
24
- config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'jms.yml'))[jms_provider]
25
- raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless config
26
-
27
- JMS::Connection.session(config) do |session|
28
- session.temporary_queue do |temporary_queue|
29
- session.consumer(:destination => temporary_queue) do |consumer|
30
- session.producer(:queue_name => "ExampleQueue") do |producer|
31
- message = session.message("Hello World")
32
- message.jms_reply_to = temporary_queue
33
- producer.send(message)
34
- end
35
- response_message = consumer.get(:timeout => 5000) # Using timeout of 5seconds here
36
- response = response_message != nil ? response_message.data : nil # Get message data as response if response_message is available
37
- p response
38
- end
39
- end
40
- end
@@ -1,51 +0,0 @@
1
- #
2
- # Example : files_to_q : Place all files in a directory to a queue
3
- # Each file is written as a separate message
4
- # Place the data in a file ending with '.data'
5
- # and the header information in a file with same name, but with an
6
- # extension of '.yml'
7
- #
8
- # jruby files_to_q.rb activemq my_queue
9
- #
10
-
11
- # Allow examples to be run in-place without requiring a gem install
12
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
13
-
14
- require 'rubygems'
15
- require 'jms'
16
- require 'yaml'
17
-
18
- raise("Required Parameters: 'jms_provider' 'queue_name' 'input_directory'") unless ARGV.count >= 2
19
- jms_provider = ARGV[0]
20
- queue_name = ARGV[1]
21
- path = ARGV[2] || queue_name
22
-
23
- # Load Connection parameters from configuration file
24
- config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'jms.yml'))[jms_provider]
25
- raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless config
26
-
27
- counter = 0
28
- # Consume all available messages on the queue
29
- JMS::Connection.session(config) do |session|
30
- session.producer(:queue_name => queue_name) do |producer|
31
- Dir.glob(File.join(path,'*.data')) do |filename|
32
- unless File.directory?(filename)
33
- printf("%5d: #{filename}\n",counter = counter + 1)
34
- data = File.open(filename, 'rb') {|file| file.read }
35
- header_filename = File.join(File.dirname(filename), File.basename(filename))
36
- header_filename = header_filename[0, header_filename.length - '.data'.length] + '.yml'
37
- header = File.exist?(header_filename) ? YAML.load_file(header_filename) : nil
38
- message = session.message(data, :bytes)
39
- if header
40
- header[:attributes].each_pair do |k,v|
41
- next if k == :jms_destination
42
- message.send("#{k}=".to_sym, v) if message.respond_to?("#{k}=".to_sym)
43
- end if header[:attributes]
44
- message.properties = header[:properties] || {}
45
- end
46
- producer.send(message)
47
- end
48
- end
49
- end
50
- end
51
- puts "Read #{counter} messages from #{path} and wrote to #{queue_name}"
@@ -1,44 +0,0 @@
1
- #
2
- # Example: q_to_files:
3
- # Copy all messages in a queue to separate files in a directory
4
- # The messages are left on the queue by
5
- #
6
- # jruby q_to_files.rb activemq my_queue
7
- #
8
-
9
- # Allow examples to be run in-place without requiring a gem install
10
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
11
-
12
- require 'rubygems'
13
- require 'jms'
14
- require 'yaml'
15
- require 'fileutils'
16
-
17
- raise("Required Parameters: 'jms_provider' 'queue_name' 'output_directory'") unless ARGV.count >= 2
18
- jms_provider = ARGV[0]
19
- queue_name = ARGV[1]
20
- path = ARGV[2] || queue_name
21
-
22
- # Load Connection parameters from configuration file
23
- config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'jms.yml'))[jms_provider]
24
- raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless config
25
-
26
- # Create supplied path if it does not exist
27
- FileUtils.mkdir_p(path)
28
-
29
- counter = 0
30
- # Consume all available messages on the queue
31
- JMS::Connection.session(config) do |session|
32
- session.browse(:queue_name => queue_name, :timeout=>1000) do |message|
33
- counter += 1
34
- filename = File.join(path, "message_%03d" % counter)
35
- File.open(filename+'.data', 'wb') {|file| file.write(message.data) }
36
- header = {
37
- :attributes => message.attributes,
38
- :properties => message.properties
39
- }
40
- File.open(filename+'.yml', 'wb') {|file| file.write(header.to_yaml) }
41
- end
42
- end
43
-
44
- puts "Saved #{counter} messages to #{path}"
@@ -1,44 +0,0 @@
1
- #
2
- # Sample ActiveMQ InVM Example:
3
- # Write to a queue and then consume the message in a separate thread
4
- #
5
- # Note: This example only works with ActiveMQ
6
- # Update the jar files path in ../jms.yml to point to your ActiveMQ installation
7
-
8
- # Allow examples to be run in-place without requiring a gem install
9
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
10
-
11
- require 'rubygems'
12
- require 'yaml'
13
- require 'jms'
14
- require 'benchmark'
15
-
16
- # Set Log4J properties file so that it does not need to be in the CLASSPATH
17
- java.lang.System.properties['log4j.configuration'] = "file://#{File.join(File.dirname(__FILE__), 'log4j.properties')}"
18
-
19
- jms_provider = 'activemq-invm'
20
-
21
- # Load Connection parameters from configuration file
22
- config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'jms.yml'))[jms_provider]
23
- raise "JMS Provider option:#{jms_provider} not found in jms.yml file" unless config
24
-
25
- JMS::Connection.start(config) do |connection|
26
- # Consume messages in a separate thread
27
- connection.on_message(:queue_name => 'ExampleQueue') do |message|
28
- JMS::logger.info "Consumed message from ExampleQueue: '#{message.data}'"
29
- end
30
-
31
- # Send a single message within a new session
32
- connection.session do |session|
33
- session.producer(:queue_name => 'ExampleQueue') do |producer|
34
- producer.send(session.message("Hello World. #{Time.now}"))
35
- end
36
- end
37
-
38
- JMS::logger.info "Put message on ExampleQueue"
39
-
40
- # Give the consume thread time to process the message before terminating
41
- sleep 1
42
-
43
- JMS::logger.info "Shutting down"
44
- end
@@ -1,58 +0,0 @@
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, logfile, 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
- # File appender
28
- log4j.appender.logfile=org.apache.log4j.RollingFileAppender
29
- log4j.appender.logfile.file=activemq.log
30
- log4j.appender.logfile.maxFileSize=10240KB
31
- log4j.appender.logfile.maxBackupIndex=5
32
- log4j.appender.logfile.append=true
33
- log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
34
- log4j.appender.logfile.layout.ConversionPattern=%d{ISO8601} %-5p: %m [%c %t]%n
35
- # use some of the following patterns to see MDC logging data
36
- #
37
- # %X{activemq.broker}
38
- # %X{activemq.connector}
39
- # %X{activemq.destination}
40
- #
41
- # e.g.
42
- #
43
- # log4j.appender.logfile.layout.ConversionPattern=%d | %-20.20X{activemq.connector} | %-5p | %m | %c | %t%n
44
-
45
- ###########
46
- # Audit log
47
- ###########
48
-
49
- log4j.additivity.org.apache.activemq.audit=false
50
- log4j.logger.org.apache.activemq.audit=INFO, audit
51
-
52
- log4j.appender.audit=org.apache.log4j.FileAppender
53
- log4j.appender.audit.file=activemq-audit.log
54
- log4j.appender.logfile.maxFileSize=10240KB
55
- log4j.appender.logfile.maxBackupIndex=5
56
- log4j.appender.audit.append=true
57
- log4j.appender.audit.layout=org.apache.log4j.PatternLayout
58
- log4j.appender.audit.layout.ConversionPattern=%d{ISO8601} %-5p: %m [%c %t]%n
data/examples/jms.yml DELETED
@@ -1,149 +0,0 @@
1
- # This YAML file contains the configuration options for several different
2
- # JMS Providers
3
- #
4
- # The Examples that ship with jruby-jms will use the entry 'activemq' unless
5
- # overriden at the command line. For example:
6
- # jruby producer.rb activemq
7
- #
8
-
9
- ---
10
- # Active MQ Centralized Broker
11
- activemq:
12
- :factory: org.apache.activemq.ActiveMQConnectionFactory
13
- :broker_url: tcp://127.0.0.1:61616
14
- :username: system
15
- :password: manager
16
- :require_jars:
17
- - ~/Applications/apache-activemq-5.5.0/activemq-all-5.5.0.jar
18
- - ~/Applications/apache-activemq-5.5.0/lib/optional/slf4j-log4j12-1.5.11.jar
19
- - ~/Applications/apache-activemq-5.5.0/lib/optional/log4j-1.2.14.jar
20
-
21
- # ActiveMQ In VM Broker (Supports messaging within a JVM instance)
22
- activemq-invm:
23
- :factory: org.apache.activemq.ActiveMQConnectionFactory
24
- :broker_url: vm://mybroker
25
- :object_message_serialization_defered: true
26
- :require_jars:
27
- - ~/Applications/apache-activemq-5.5.0/activemq-all-5.5.0.jar
28
- - ~/Applications/apache-activemq-5.5.0/lib/optional/slf4j-log4j12-1.5.11.jar
29
- - ~/Applications/apache-activemq-5.5.0/lib/optional/log4j-1.2.14.jar
30
-
31
- # ActiveMQ with failover to slave instance
32
- activemq-ha:
33
- :factory: org.apache.activemq.ActiveMQConnectionFactory
34
- :broker_url: failover://(tcp://msg1:61616,tcp://msg2:61616)?randomize=false&timeout=30000&initialReconnectDelay=100&useExponentialBackOff=true
35
- :require_jars:
36
- - ~/Applications/apache-activemq-5.5.0/activemq-all-5.5.0.jar
37
- - ~/Applications/apache-activemq-5.5.0/lib/optional/slf4j-log4j12-1.5.11.jar
38
- - ~/Applications/apache-activemq-5.5.0/lib/optional/log4j-1.2.14.jar
39
-
40
- # JBoss 4 Messaging
41
- :jndi_name: ConnectionFactory
42
- :jndi_context:
43
- java.naming.factory.initial: org.jnp.interfaces.NamingContextFactory
44
- java.naming.provider.url: jnp://localhost:1099
45
- java.naming.security.principal: user
46
- java.naming.security.credentials: pwd
47
- :require_jars:
48
- - ~/Applications/jboss-messaging-client/1.4.0.SP3/javassist.jar
49
- - ~/Applications/jboss-messaging-client/1.4.0.SP3/jboss-aop-jdk50.jar
50
- - ~/Applications/jboss-messaging-client/1.4.0.SP3/jboss-messaging-client.jar
51
- - ~/Applications/jboss-messaging-client/1.4.0.SP3/jbossall-client.jar
52
- - ~/Applications/jboss-messaging-client/1.4.0.SP3/trove.jar
53
-
54
- # Apache Qpid
55
- qpid:
56
- :jndi_name: local
57
- :jndi_context:
58
- java.naming.factory.initial: org.apache.qpid.jndi.PropertiesFileInitialContextFactory
59
- connectionfactory.local: amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5672'
60
- :require_jars:
61
- - ~/Applications/javax.jms.jar
62
- - ~/Applications/qpid-0.8/lib/backport-util-concurrent-2.2.jar
63
- - ~/Applications/qpid-0.8/lib/commons-collections-3.2.jar
64
- - ~/Applications/qpid-0.8/lib/commons-lang-2.2.jar
65
- - ~/Applications/qpid-0.8/lib/mina-core-1.0.1.jar
66
- - ~/Applications/qpid-0.8/lib/qpid-client-0.8.jar
67
- - ~/Applications/qpid-0.8/lib/qpid-common-0.8.jar
68
- - ~/Applications/qpid-0.8/lib/slf4j-api-1.6.1.jar
69
- - ~/Applications/qpid-0.8/lib/log4j-1.2.12.jar
70
- - ~/Applications/qpid-0.8/lib/slf4j-log4j12-1.6.1.jar
71
-
72
- # HornetQ Broker
73
- hornetq:
74
- # Connect to a local HornetQ Broker using JNDI
75
- :jndi_name: /ConnectionFactory
76
- :jndi_context:
77
- java.naming.factory.initial: org.jnp.interfaces.NamingContextFactory
78
- java.naming.provider.url: jnp://localhost:1099
79
- java.naming.factory.url.pkgs: org.jboss.naming:org.jnp.interfaces
80
- java.naming.security.principal: guest
81
- java.naming.security.credentials: guest
82
- :require_jars:
83
- - ~/Applications/hornetq-2.4.0.Final/lib/hornetq-commons.jar
84
- - ~/Applications/hornetq-2.4.0.Final/lib/hornetq-core-client.jar
85
- - ~/Applications/hornetq-2.4.0.Final/lib/hornetq-jms-client.jar
86
- - ~/Applications/hornetq-2.4.0.Final/lib/jboss-jms-api.jar
87
- - ~/Applications/hornetq-2.4.0.Final/lib/jnp-client.jar
88
- - ~/Applications/hornetq-2.4.0.Final/lib/netty.jar
89
-
90
- # Tibco EMS
91
- ems:
92
- :jndi_name: TestFactory
93
- :jndi_context:
94
- java.naming.factory.initial: com.tibco.tibjms.naming.TibjmsInitialContextFactory
95
- java.naming.provider.url: tcp://localhost:7222
96
- :require_jars:
97
- - C:\tibco\ems\8.0\lib\jms-2.0.jar
98
- - C:\tibco\ems\8.0\lib\tibjms.jar
99
- - C:\tibco\ems\8.0\lib\tibcrypt.jar
100
-
101
- # IBM WebSphere MQ
102
- wmq:
103
- :factory: com.ibm.mq.jms.MQQueueConnectionFactory
104
- :queue_manager: LOCAL
105
- :host_name: localhost
106
- :channel: MY.CLIENT.CHL
107
- :port: 1414
108
- # Transport Type: com.ibm.mq.jms.JMSC::MQJMS_TP_CLIENT_MQ_TCPIP
109
- :transport_type: 1
110
- :username: mqm
111
- :require_jars:
112
- - /opt/mqm/lib/com.ibm.mqjms.jar
113
-
114
- # Oracle AQ 9
115
- oracleaq:
116
- :factory: 'JMS::OracleAQConnectionFactory'
117
- :url: 'jdbc:oracle:thin:@hostname:1521:instanceid'
118
- :username: 'aquser'
119
- :password: 'mypassword'
120
- :require_jars:
121
- - ~/Applications/oraclestreams/ojdbc6.jar
122
- - ~/Applications/oraclestreams/jmscommon.jar
123
- - ~/Applications/oraclestreams/aqapi.jar
124
- - ~/Applications/oraclestreams/xdb.jar
125
- - ~/Applications/oraclestreams/jta.jar
126
-
127
- oracleaq_simple:
128
- :factory: 'JMS::OracleAQConnectionFactory'
129
- :url: 'jdbc:oracle:thin:aquser/mypassword@hostname:1521:instanceid'
130
- :require_jars:
131
- - ~/Applications/oraclestreams/ojdbc6.jar
132
- - ~/Applications/oraclestreams/jmscommon.jar
133
- - ~/Applications/oraclestreams/aqapi.jar
134
- - ~/Applications/oraclestreams/xdb.jar
135
- - ~/Applications/oraclestreams/jta.jar
136
-
137
- oracleaq_jndi:
138
- :jndi_name: ConnectionFactory
139
- :jndi_context:
140
- java.naming.factory.initial: oracle.jms.AQjmsInitialContextFactory
141
- java.naming.security.principal: aquser
142
- java.naming.security.credentials: mypassword
143
- db_url: jdbc:oracle:thin:@hostname:1521:instanceid
144
- :require_jars:
145
- - ~/Applications/oraclestreams/ojdbc6.jar
146
- - ~/Applications/oraclestreams/jmscommon.jar
147
- - ~/Applications/oraclestreams/aqapi.jar
148
- - ~/Applications/oraclestreams/xdb.jar
149
- - ~/Applications/oraclestreams/jta.jar