Hi,
>I tried to create a physical destination named "Destination"
According to your code it should be called "testDestination".
You also seem to miss "mappedName" from the @MessageDriven Annotation.
Below is an example that works for me.
Hope it helps.
good luck!
wim
@MessageDriven(mappedName = "jms/ testDestination", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode",
propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "subscriptionDurability",
propertyValue = "Durable"),
@ActivationConfigProperty(propertyName = "clientId", propertyValue =
" NotificationListenerBean"),
@ActivationConfigProperty(propertyName = "subscriptionName",
propertyValue = " NotificationListenerBean")
})
public class NotificationListenerBean implements MessageListener {
@Resource
private MessageDrivenContext mdc;
public void onMessage(Message inMessage) {
...
}
}
-----Original Message-----
From: glassfish_at_javadesktop.org [mailto:glassfish_at_javadesktop.org]
Sent: dinsdag 11 november 2008 0:24
To: users_at_glassfish.dev.java.net
Subject: [JMS] MDB problem - cannot make this work
Hi.
I wanted to take a look at JMS with Glassfish. The idea is simple - a
servlet has the Notifier bean injected, calls the doNotify() method on it,
which sends a message via JMS, which is handled by the MDB, and printed to
standard output.
I logged into the admin console and created two resources:
1. Resources -> JMS Resources -> Connection Factories: I created it with a
name "jms/topicFactory" and type "javax.jms.TopicConnectionFactory", deleted
the properties "UserName" and "Password"
2. Resources -> JMS Resources -> Destination Resources: mine is called
"jms/testDestination" and is of type "javax.jms.Topic", it has a "Name"
property with "Destination" as the value - this was created by default,
there is a message at the top of the page that the Name property specifies
some physical destination (?)
The interface / bean producing the messages look like this:
[code]
package ejb;
import javax.ejb.Remote;
@Remote
public interface Notifier {
void doNotify(String notification);
}
package ejb;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
@Stateless
public class JMSNotifierBean implements Notifier {
@Resource(mappedName = "jms/topicFactory")
private TopicConnectionFactory connectionFactory;
@Resource(mappedName = "jms/testDestination")
private Topic topic;
private TopicConnection connection;
@Override
public void doNotify(String notification) {
try {
Session s = connection.createSession(true,
Session.AUTO_ACKNOWLEDGE);
MessageProducer p = s.createProducer(topic);
TextMessage tm = s.createTextMessage("<<< " + notification + "
>>>");
p.send(tm);
p.close();
s.close();
} catch (JMSException exc) {
exc.printStackTrace();
}
}
@PostConstruct
public void initialize() {
try {
connection = connectionFactory.createTopicConnection();
} catch (JMSException exc) {
exc.printStackTrace();
}
}
@PreDestroy
public void destroy() {
try {
connection.close();
} catch (JMSException exc) {
exc.printStackTrace();
}
}
}
[/code]
And the Message Driven Bean:
[code]
package ejb;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destinationName",
propertyValue = "jms/testDestination")
})
public class NotificationListenerBean implements MessageListener {
@Override
public void onMessage(Message msg) {
System.out.println(msg);
}
}
[/code]
However, this doesn't work - when deploying this application (in Eclipse, I
get this exception):
[code]
[#|2008-11-10T23:47:50.682+0100|SEVERE|sun-appserver9.1|javax.enterprise.sys
tem.container.ejb.mdb|_ThreadID=17;
_ThreadName=httpWorkerThread-4848-0;_RequestID=0d22116a-556e-4705-97ce-bcf58
a27c639;|com.sun.enterprise.connectors.ConnectorRuntimeException
com.sun.enterprise.connectors.ConnectorRuntimeException: JMS resource not
created :
at
com.sun.enterprise.connectors.system.ActiveJmsResourceAdapter.getPhysicalDes
tinationFromConfiguration(ActiveJmsResourceAdapter.java:1546)
at
com.sun.enterprise.connectors.system.ActiveJmsResourceAdapter.updateMDBRunti
meInfo(ActiveJmsResourceAdapter.java:1380)
at
com.sun.enterprise.connectors.inflow.ConnectorMessageBeanClient.setup(Connec
torMessageBeanClient.java:170)
at
com.sun.ejb.containers.MessageBeanContainer.<init>(MessageBeanContainer.java
:209)
at
com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactory
Impl.java:280)
at
com.sun.enterprise.server.AbstractLoader.loadEjbs(AbstractLoader.java:536)
at
com.sun.enterprise.server.ApplicationLoader.doLoad(ApplicationLoader.java:18
8)
at
com.sun.enterprise.server.TomcatApplicationLoader.doLoad(TomcatApplicationLo
ader.java:126)
at
com.sun.enterprise.server.AbstractLoader.load(AbstractLoader.java:244)
at
com.sun.enterprise.server.ApplicationManager.applicationDeployed(Application
Manager.java:336)
at
com.sun.enterprise.server.ApplicationManager.applicationDeployed(Application
Manager.java:210)
at
com.sun.enterprise.server.ApplicationManager.applicationDeployed(Application
Manager.java:645)
at
com.sun.enterprise.admin.event.AdminEventMulticaster.invokeApplicationDeploy
EventListener(AdminEventMulticaster.java:928)
at
com.sun.enterprise.admin.event.AdminEventMulticaster.handleApplicationDeploy
Event(AdminEventMulticaster.java:912)
at
com.sun.enterprise.admin.event.AdminEventMulticaster.processEvent(AdminEvent
Multicaster.java:461)
at
com.sun.enterprise.admin.event.AdminEventMulticaster.multicastEvent(AdminEve
ntMulticaster.java:176)
at
com.sun.enterprise.admin.server.core.DeploymentNotificationHelper.multicastE
vent(DeploymentNotificationHelper.java:308)
at
com.sun.enterprise.deployment.phasing.DeploymentServiceUtils.multicastEvent(
DeploymentServiceUtils.java:226)
at
com.sun.enterprise.deployment.phasing.ServerDeploymentTarget.sendStartEvent(
ServerDeploymentTarget.java:298)
at
com.sun.enterprise.deployment.phasing.ApplicationStartPhase.runPhase(Applica
tionStartPhase.java:132)
at
com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(Deploymen
tPhase.java:108)
at
com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDe
ploymentService.java:919)
at
com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeployment
Service.java:591)
at
com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeployment
Service.java:635)
at
com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.start(ApplicationsCo
nfigMBean.java:744)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:
375)
at
com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:
358)
at
com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:
464)
at
com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanSer
verInterceptor.java:836)
at
com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:90)
at $Proxy1.invoke(Unknown Source)
at
com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInte
rceptor.java:304)
at
com.sun.enterprise.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.
java:174)
at
com.sun.enterprise.admin.jmx.remote.server.callers.InvokeCaller.call(InvokeC
aller.java:69)
at
com.sun.enterprise.admin.jmx.remote.server.MBeanServerRequestHandler.handle(
MBeanServerRequestHandler.java:155)
at
com.sun.enterprise.admin.jmx.remote.server.servlet.RemoteJmxConnectorServlet
.processRequest(RemoteJmxConnectorServlet.java:122)
at
com.sun.enterprise.admin.jmx.remote.server.servlet.RemoteJmxConnectorServlet
.doPost(RemoteJmxConnectorServlet.java:193)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFi
lterChain.java:411)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:290)
at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContext
Valve.java:271)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:202)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632
)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577
)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206
)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632
)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577
)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:150)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632
)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577
)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(
DefaultProcessorTask.java:637)
at
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(Defa
ultProcessorTask.java:568)
at
com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(Defaul
tProcessorTask.java:813)
at
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTas
k(DefaultReadTask.java:341)
at
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadT
ask.java:263)
at
com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadT
ask.java:214)
at
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at
com.sun.enterprise.web.connector.grizzly.WorkerThreadImpl.run(WorkerThreadIm
pl.java:116)
|#]
[/code]
The official Java EE 5 tutorial states:
"In the Application Server implementation of JMS, each destination resource
refers to a physical
destination. You can create a physical destination explicitly, but if you do
not, the Application
Server creates it when it is needed and deletes it when you delete the
destination resource." (page 902, the very last paragraph)
This doesn't work for me. The only physical destination in Configuration ->
Java Message Service is mq.sys.dmq, which is always there. I tried to create
a physical destination named "Destination" (to reflect the Name property of
the destination resource I created), but no change in behaviour.
Could someone please help me out and tell me what is wrong here?
Thanks.
[Message sent by forum member 'szczyp' (szczyp)]
http://forums.java.net/jive/thread.jspa?messageID=315915
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net