[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-4235) Improve asynchronous JMS support
Dan Allen (JIRA)
jira-events at lists.jboss.org
Thu Jun 11 19:30:56 EDT 2009
[ https://jira.jboss.org/jira/browse/JBSEAM-4235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12471790#action_12471790 ]
Dan Allen commented on JBSEAM-4235:
-----------------------------------
I have a prototype available in Seam 2.1 and 2.2 branches (SVN). This is a tough problem because the invocation of an MDB is fundamentally different from a session bean or any other component. Instead of the application getting a reference and invoking the instance, it's the container that does this work. Thus, there is little opportunity for Seam to get its hands in there and enhance it. Simply adding @Asynchronous to the onMessage() method won't do anything at all.
I have come up with two approaches that will work.
#1. An EJB interceptor - ContextualMessageHandlerRequestInterceptor
Apply this interceptor to your MDB as follows:
@Interceptor(ContextualMessageHandlerRequestInterceptor.class)
public class MyListener implements MessageListener { ... }
Now you can use Component.getInstance() from within onMessage() to look up request-scoped, application-scoped, or business-process scoped components. To use a business-scoped component, you must pass either taskId or processId as a Long property in the payload of the message object.
#2. A contextual callback
Alternatively, you can use the technique that the interceptor uses to execute code within the boundaries of a Seam life cycle. There is some convenience baked in. You can provide as a type parameter the type you want to pass to Component.getInstance() to retrieve your delegate component.
try
{
new ContextualMessageHandlerRequest<MyMessageProcessor>(message) {
@Override
public void process() throws Exception {
getDelegate().process(getTextMessage().getText());
}
}.run();
} catch (Exception e) {
// log me or something
}
Internally, this will call:
((MyMessageProcessor) Component.getInstance(MyMessageProcessor.class)).process((TextMessage) message).getText());
Let me know what you think about these solutions.
> Improve asynchronous JMS support
> --------------------------------
>
> Key: JBSEAM-4235
> URL: https://jira.jboss.org/jira/browse/JBSEAM-4235
> Project: Seam
> Issue Type: Feature Request
> Components: Async
> Affects Versions: The future
> Environment: JBOSS 5.0 with Seam 2.1
> Reporter: Leo van den berg
> Fix For: The future
>
>
> At the moment Seam doesn't fully support the use of asynchronous messaging within the server environment. A proposed solution is to add the same type of support to "JMS-enabled" beans as is available for the timers (EJB and Quartz). It should be possible to simply add the @Asynchronous annotation to the onMessage method and have the Seam components available in the same way.
> At the moment this is only possible with some tricks (as suggested in mentioned Seam forum thread by Dan Allen), but it would be a good extension to JMS to have it as standard functionality available.
> Additionally examles could be added to the documentation and examples-directory of the download to show how to use asynchronous JMS-messaging in a Seam-application.
>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the seam-issues
mailing list