users@glassfish.java.net

JMS: GF <- remote OpenMQ with dynamic configuration?

From: <glassfish_at_javadesktop.org>
Date: Wed, 07 Oct 2009 08:01:11 PDT

Hi,

I'm banging my head on this for days and can't get anything out of the evailable documentation:

What I want to do is have a MDB consume from a foreign Queue. The Queue will be on a Sonic MQ but for now I'd be happy to get it done with a OpenMQ.

My Setup:
- Glassfish v3 b65+
- local OpenMQ in EMBEDDED mode
- remote OpenMQ: "imqbrokerd -port 7677"
- RESTful WebService to push a message into the remote Queue
- local MessageDrivenBean to receive that message

My Achievement so far:
[b]1. Have a message pushed into the Queue:[/b]
[i]
@Stateless // ohne dies funktioniert DI nicht!
@Path("/jms") // Pfad, welcher an context root angehÃĪngt, wird, hier also http://localhost:8080/webservicetest/jms
public class JMSRestfulWebService {
...
    @Resource(mappedName = "jms/MyRemoteConnFactory")
    private ConnectionFactory remoteConnectionFactory;

    @Resource(mappedName = "jms/MyRemoteQueue")
    private Queue remoteQueue;
...
    @Path("remote")
    @GET
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public String putMessageRemote() throws NamingException, JMSException, NotSupportedException, SystemException, SecurityException, IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
    {
        System.out.println("called putMessageRemote");
        
        javax.jms.Connection connection = remoteConnectionFactory.createConnection();
        javax.jms.Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
        MessageProducer messageProducer = session.createProducer(remoteQueue);
        {
            TextMessage message = session.createTextMessage();
            message.setText("Hello, remote JMS!");
            messageProducer.send(message);
        }
        
        return "JMS remotely produced 1 message.";
    }
}
[/i]
[b]2. Have a MDB consume that message with a sstatic configuration:[/b]
[i]
@MessageDriven(
        activationConfig = {
                @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
                @ActivationConfigProperty(propertyName = "addressList", propertyValue = "mq://localhost:7677")
        },
        mappedName = "jms/MyRemoteQueue")
public class MyStaticRemoteMessageDrivenBean implements MessageListener {
...
    public void onMessage(Message message) {
        try {
            System.out.println("JCA MDB got message:" + ((TextMessage)message).getText());
        } catch (JMSException e) {
            e.printStackTrace();
        }
        
    }

}
[/i]
So far so good.

Now I want to get rid of the static configuration of the "adressList". This should be configured in the application server - NOT in the deployed artifact. So neither ejb-jar.xml nor sun-ejb-jar.xml is an option. I don't want an extra configuration file, either.

So I went on through genericra, imqimsra.rar and sun-jms-adapter.rar but couldn't get a working solution done.
The best I could find was this http://wikis.sun.com/download/attachments/47881337/JCAMDBsForeignJMSBrokers1_0.pdf but its wizards hide important information about the JCA configuration.
This https://jmsjca.dev.java.net/source/browse/*checkout*/jmsjca/jmsjca/unifiedjms/src/userdoc/sun-jms-adapter-readme.html looks good, too but it doesn't have an example of a configuration.
It led me to this:
[i]
 asadmin create-resource-adapter-config sun-jms-adapter
 asadmin deploy \temp\downloads\sun-jms-adapter.rar

 asadmin create-connector-connection-pool --raname sun-jms-adapter --connectiondefinition javax.jms.ConnectionFactory --property ConnectionURL=mq\://localhost\:7677:destination=jms/AdapterQueue jms/AdapterConnectionPool
 asadmin create-connector-resource --poolname jms/AdapterConnectionPool jms/AdapterConnectionFactory

 asadmin create-admin-object --raname sun-jms-adapter --restype javax.jms.Queue --property DestinationProperties=Name\=AdapterQueue jms/AdapterQueue
 asadmin create-jmsdest --desttype queue AdapterQueue
[/i]
plus the MDB:
[i]
@MessageDriven(
        activationConfig = {
                @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        },
        mappedName = "jms/AdapterQueue")
public class MyAdapterRemoteMessageDrivenBean implements MessageListener {
{
...
}
[/i]
plus sun-ejb-jar.xml:
[i]
<enterprise-beans>
<ejb>
<ejb-name>MyAdapterRemoteMessageDrivenBean</ejb-name>
<mdb-resource-adapter>
<resource-adapter-mid>sun-jms-adapter</resource-adapter-mid>
<activation-config>
        <activation-config-property>
          <activation-config-property-name>ConnectionURL</activation-config-property-name>
          <activation-config-property-value>mq://localhost:7677</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
          <activation-config-property-name>destination</activation-config-property-name>
          <activation-config-property-value>jms/AdapterQueue</activation-config-property-value>
        </activation-config-property>
</activation-config>
</mdb-resource-adapter>
       
</ejb>
</enterprise-beans>
[/i]
But that just gives me a:
[i]
JMSJCA-E057: TxMgr could not be obtained: JMSJCA-E152: Could not find transaction manager adapter
javax.resource.ResourceException: JMSJCA-E057: TxMgr could not be obtained: JMSJCA-E152: Could not find transaction manager adapter
    at com.stc.jmsjca.util.Exc.rsrcExc(Exc.java:74)
    at com.stc.jmsjca.core.Delivery.<init>(Delivery.java:583)
    at com.stc.jmsjca.core.SyncDelivery.<init>(SyncDelivery.java:125)
    at com.stc.jmsjca.core.RAJMSObjectFactory.createDelivery(RAJMSObjectFactory.java:913)
    at com.stc.jmsjca.core.Activation.createDelivery(Activation.java:502)
    at com.stc.jmsjca.core.Activation.asyncStart(Activation.java:543)
    at com.stc.jmsjca.core.Activation.access$000(Activation.java:81)
    at com.stc.jmsjca.core.Activation$1.run(Activation.java:347)
    at java.lang.Thread.run(Thread.java:619)
[/i]
    
Could anybody give me a working example for this?

Cheers,

Matthias

P.S. Sorry for missing white spaces, I think they get eaten by the forum software?
[Message sent by forum member 'matthiasfraass' (matthias.fraass_at_tricoder.net)]

http://forums.java.net/jive/thread.jspa?messageID=367134