As you can see, you import the needed Java classes and create two Ruby classes that are
MessageListeners. The onMessage method just dispatches to the handle_response and
handle_request methods on the Communication module. You need a way of killing logging
CHAPTER 13 ?– JRUBY AND MESSAGE-ORIENTED SYSTEMS 248
until you start using this application together with the other JMS application, so you do that as
you did in Java:
def self.kill_logging
enm = java.util.logging.LogManager.log_manager.logger_names
while enm.hasMoreElements
java.util.logging.Logger.getLogger(
enm.nextElement).level = java.util.logging.Level::OFF
end
end
Obviously, the code is a little more readable in Ruby format.
You??™ll create two consumers, so add a helper method for doing that:
def self.create_consumer(ctx, name, listener_class)
dest = ctx.lookup(name)
conn = @conn_factory.create_connection
session = conn.create_session(false, Session::AUTO_ACKNOWLEDGE)
consumer = session.create_consumer(dest)
listener = listener_class.new
consumer.setMessageListener(listener)
conn.start
return dest, conn, session, consumer, listener
end
This code expects there to be an instance variable called @conn_factory before the
method gets called. It creates the connection, session, and listener; adds the listener to the
consumer; and starts the connection, finally returning all values of interest to the caller.
A user of this library should call the start message to get everything going:
def self.
Pages:
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371