users@glassfish.java.net

Re: Trouble connecting MDB to external JMS destination

From: Comerford, Sean <Sean.Comerford_at_espn.com>
Date: Tue, 26 Jun 2012 00:10:04 -0400

Hey Martin,

I don't think it's classpath or dest related - my app on this GF is successfully able to send/receive messages with the topic in question but that's using @Resource injection of factory + topic.

And if I list all the config for the MDB in a sun-ejb.xml it will work.

However that's not desirable as the config is environment specific - hence I want MDB to reference JNDI name only.

But as soon as I try annotation config it blows up.

I suspect my problem is I need to tell the MDB my destination is managed by the wmq.jmsra connector and NOT the default / built in generic adapter.

But I only know how to do that via the sun-ejb

Or perhaps i need to use the activation config which JMS connection factory to use.

Any ideas on either of those angles?

On Jun 25, 2012, at 8:33 PM, "Martin Gainty"<@hotmail.com> wrote:

Hi Sean

stupid question but i have to ask did you
copy all glassfish/lib/install/applications/jmsra/*.jar to glassfish/lib/*.jar

create the jmsdest?

check the jmsdest
>/imq/bin/imqadmin.exe

if you dont see your jmsdest then you can create one
>asadmin create-jmsdest

if you get tripped up by GF not finding the IMQ jars you can start GF with Application Specific Library loading with
 --libraries option

Martin
______________________________________________
Old Man: First we must learn to walk then we can run
Young man: you mean like driving on driving on Route 10 before driving on Route 84?
Old Man: ..more like working for Yes Network then working for ESPN



________________________________
From: <mailto:Sean.Comerford_at_espn.com> Sean.Comerford_at_espn.com<mailto:Sean.Comerford_at_espn.com>
To: <mailto:users_at_glassfish.java.net> users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>
Date: Mon, 25 Jun 2012 18:23:23 -0400
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.<init>(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<http://ESPN.com> Architecture & Platforms