Skip to main content

Trouble connecting MDB to external JMS destination

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
7 replies [Last post]
Comerford, Sean...
Offline
Joined: 2010-11-05

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nigeldeakin
Offline
Joined: 2007-10-12

Comerford, Sean...
Offline
Joined: 2010-11-05

nigeldeakin
Offline
Joined: 2007-10-12

mgainty
Offline
Joined: 2004-05-21

David Zhao

Hi Sean,

Could you please try by adding a property Name which value is the physical destination in MQ (SEAN.TEST for this case) when you create the admin object jms/UTTopic? For example,

asadmin create-admin-object --restype javax.jms.Topic --classname com.ibm.mq.connector.outbound.MQTopicProxy --property DestinationJndiName=:Name=SEAN.TEST --raname wmqjmsra jms/UTTopic

Thanks,

David Zhao

From: Comerford, Sean [mailto:Sean.Comerford@espn.com]
Sent: Tuesday, June 26, 2012 6:23 AM
To: users@glassfish.java.net
Subject: Trouble connecting MDB to external JMS destination

Using GF 3.1 here.

I have a Websphere MQ connection pool and factory defined on my GF instance using IBM's wmq.jmsra RAR.

I can publish using this simple servlet code below.

@Resource(mappedName = "jms/UTTopicFactory")

private TopicConnectionFactory topicConnectionFactory;

@Resource(mappedName = "jms/UTTopic")

private Topic topic;

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

try {

String msgText = request.getParameter("msgText");

sendToTopic(msgText);

} catch (Exception e) {

out.print(e.toString());

}

}

private void sendToTopic(String msgText) throws Exception {

TopicConnection connection = topicConnectionFactory.createTopicConnection();

TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

MessageProducer messageProducer = session.createProducer(topic);

TextMessage textMessage = session.createTextMessage();

textMessage.setText(msgText);

messageProducer.send(textMessage, DeliveryMode.PERSISTENT, TextMessage.DEFAULT_PRIORITY, 1000);

messageProducer.send(textMessage);

messageProducer.close();

session.close();

connection.close();

}

And I read from it using this simple servlet:

@Resource(mappedName = "jms/UTTopicFactory")

private TopicConnectionFactory topicConnectionFactory;

@Resource(mappedName = "jms/UTTopic")

private Topic topic;

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

try {

out.write("Topic response = " + readTopic());

} catch (Exception e) {

out.write("Error: " + e.getMessage());

e.printStackTrace();

} finally {

out.close();

}

}

private String readTopic() throws Exception {

String result = null;

TopicConnection connection = topicConnectionFactory.createTopicConnection();

TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

TopicSubscriber subscriber = session.createDurableSubscriber(topic, "SEAN.TEST");

connection.start();

TextMessage textMessage = (TextMessage) subscriber.receive(10000);

if (textMessage != null) {

System.out.println("Got " + textMessage.getText());

result = "Retrieved message from topic: " + textMessage.getText();

textMessage.acknowledge();

} else {

System.out.println("No messages in topic");

result = "No messages in topic";

}

subscriber.close();

session.close();

connection.close();

return result;

}

My (possibly dumb) question is how do I create a MDB that talks to the topic in the same way as the servlet above - by just referencing the JNDI name. Tried this:

@MessageDriven(mappedName = "jms/UTTopic", activationConfig = {

@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),

@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),

@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),

@ActivationConfigProperty(propertyName = "clientId", propertyValue = "MyMDB"),

@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "SEAN.TEST")

})

public class MyMDB implements MessageListener {

public MyMDB() {

}

@Override

public void onMessage(Message message) {

}

}

But this won't deploy properly - yields:

SEVERE: Exception while loading the app : EJB Container initialization error

com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Could not find physical destination : null

at com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter.getPhysicalDestinationFromConfiguration(ActiveJmsResourceAdapter.java:2068)

at com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter.updateMDBRuntimeInfo(ActiveJmsResourceAdapter.java:1864)

at com.sun.enterprise.connectors.inbound.ConnectorMessageBeanClient.setup(ConnectorMessageBeanClient.java:186)

at com.sun.ejb.containers.MessageBeanContainer.(MessageBeanContainer.java:205)

at com.sun.ejb.containers.ContainerFactoryImpl.createContainer(ContainerFactoryImpl.java:121)

at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:230)

at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:290)

at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:101)

at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:186)

at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:257)

at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:461)

at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)

at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:382)

at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:355)

at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:370)

at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1064)

at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:96)

at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1244)

at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1232)

at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:459)

at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:209)

at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:168)

at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)

at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:238)

at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)

at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)

at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)

at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)

at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

at java.lang.Thread.run(Thread.java:680)

Bear in mind the topic here is an EXTERNAL topic being provided by the web sphere MQ resource adapter.

Any help?

---

Sean Comerford

ESPN.com Architecture & Platforms

mgainty
Offline
Joined: 2004-05-21

Comerford, Sean...
Offline
Joined: 2010-11-05