SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 345 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

What??™s interesting is that only the configuration needs
to change if you change provider or adapter. This makes ActiveMessaging highly useful for
tying Rails applications into MOM systems.
JRuby and Message-Driven Beans
As the second sidetrack on our track to a message-driven application, we??™ll take a quick look
at using JRuby with J2EE MDBs. In fact, the legacy system is implemented as a pure Java MDB,
so you??™ll soon see how interaction with such an MDB works. The second way to use JRuby with
MDBs is by doing the same as you did with a stateless session bean in Chapter 9. A simple
MDB that doesn??™t do anything at all looks like this in Java:
package com.book;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.annotation.Resource;
import javax.ejb.MessageDriven;
import javax.ejb.MessageDrivenContext;
@MessageDriven(mappedName = "TheQueueOrTopicName")
public class AMessageDrivenBean implements MessageListener {
@Resource
private MessageDrivenContext mdc;
public AMessageDrivenBean() {
}
public void onMessage(Message msg) {
}
}
CHAPTER 13 ?–  JRUBY AND MESSAGE-ORIENTED SYSTEMS 236
So, to create an MDB, the class needs to implement MessageListener, and you need to
provide the MessageDriven annotation. The MessageDriven annotation takes as the argument
mappedName, which defines which queue or topic this MDB should listen to. You can also use
the Resource annotation to inject the MessageDrivenContext into the application, if you need
to get hold of any services the container provides.


Pages:
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357