JMS and peristent messages

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

JMS and peristent messages

Markus Lutum
Hi out there!

I have a question how I can get a JMS Message persistent in the Database.

I am using the following configuration:
(default I think)

<Container id="My MDB Container" type="MESSAGE">
  #  The resource adapter delivers messages to the container
  ResourceAdapter My JMS Resource Adapter

  # Specifies the message listener interface handled by this container
  MessageListenerInterface javax.jms.MessageListener

  # Specifies the activation spec class
  ActivationSpecClass org.apache.activemq.ra.ActiveMQActivationSpec

  # Specifies the maximum number of bean instances that are
  # allowed to exist for each MDB deployment.
  InstanceLimit 10
</Container>

<Resource id="My JMS Resource Adapter" type="ActiveMQResourceAdapter">
  # Broker configuration URI as defined by ActiveMQ
  # see http://activemq.apache.org/broker-configuration-uri.html
  #BrokerXmlConfig xbean:file:conf/activemq.xml
  BrokerXmlConfig broker:(tcp://localhost:61616)?useJmx=false&amp;persistent=true

  # Broker address
  ServerUrl vm://localhost?async=true
  MaximumRedeliveries 10
  InitialRedeliveryDelay 3000

  # DataSource for persistence messages (Links to my HSQL Database)
  DataSource My Unmanaged DataSource
</Resource>

<Connector id="My JMS Connection Factory" type="javax.jms.ConnectionFactory">
  ResourceAdapter My JMS Resource Adapter
  TransactionSupport xa
  PoolMaxSize 10
  PoolMinSize 0
  ConnectionMaxWaitMilliseconds 5000
  ConnectionMaxIdleMinutes 15
</Connector>


Now I try to write messages to a queue using a session bean.

....
    @Resource
    private ConnectionFactory connectionFactory;

    @Resource(name="testQueue")
    private Queue testQueue;

....
            connection = connectionFactory.createConnection();
            connection.start();

            // Create a Session
            session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);

            // Create a MessageProducer from the Session to the Topic or Queue
            MessageProducer producer = session.createProducer(testQueue);
            producer.setDeliveryMode(DeliveryMode.PERSISTENT);

            // Create a message
            TextMessage message = session.createTextMessage("test");

            // Tell the producer to send the message
            producer.send(message);

BUT the messages are not backed up by the database.
There is no JMS related Table created and so also no entry is stored.
WHY?

When I consume the message it works. So it is stored only in memory.
What do I miss?

Greets
Markus  Lutum


Reply | Threaded
Open this post in threaded view
|

Re: JMS and peristent messages

Bjorn Danielsson
Markus Lutum <[hidden email]> wrote:

>
> I have a question how I can get a JMS Message persistent in the Database.
>
> I am using the following configuration:
> (default I think)
>[...]
> <Resource id="My JMS Resource Adapter" type="ActiveMQResourceAdapter">
>   # Broker configuration URI as defined by ActiveMQ
>   # see http://activemq.apache.org/broker-configuration-uri.html
>   #BrokerXmlConfig xbean:file:conf/activemq.xml
>   BrokerXmlConfig broker:(tcp://localhost:61616)?useJmx=false&amp;persistent=true
>[...]

I looked into this since I also want persistant JMS. I found that
there is some code in BrokerServer.java (openejb-3.1.x branch)
which intercepts a "broker:" URI and runs some special code in
that case. Not sure exactly what the code does, but it stops JMS
persistence from working.

I found that if you let the BrokerXmlConfig property be an
empty string, then ActiveMQ will use its default configuration
which persists JMS messages by logging them in a KahaDB database
under the directory "activemq-data" which is automatically
created when ActiveMQ is initialized.

You don't get JDBC persistence unless ActiveMQ is explicitly
configured for that. I guess an "xbean:" URI is needed for
that, but I haven't tried this myself.

--
Bjorn Danielsson
Cuspy Code AB
Reply | Threaded
Open this post in threaded view
|

Re: JMS and peristent messages

Bjorn Danielsson
Update:

I wrote:
> You don't get JDBC persistence unless ActiveMQ is explicitly
> configured for that. I guess an "xbean:" URI is needed for
> that, but I haven't tried this myself.

OK, now I have tried.

It turns out that using an "xbean:" URI for BrokerXmlConfig
requires adding Spring libraries to OpenEJB in order to work.

But there is a third alternative, the "properties:" URI.
Unfortunately the ActiveMQ documentation is hard to penetrate,
I had to find javadocs and do some trial and error in order
to figure out which properties are (or might be) available.

Here is the configuration I ended up with. First, openejb.xml:

BrokerXmlConfig properties:file:/opt/openejb/conf/activemq.properties

I tried using ${openejb.base} in the file path, but that didn't
work. Don't know if that is a bug or a candidate for a feature
request :-)

Then I created the file activemq.properties:

useJmx = false
persistent = true
dataDirectory = /opt/openejb/data/activemq
transportConnectorURIs = tcp://localhost:61616

Yet again, ${openejb.base} doesn't work, or rather it results
in a directory with the literal name "${openejb.base}" being
created in the currently connected directory when openejb is
started. I would assume that string interpolation in this file
most likely needs code changes in the ActiveMQ source.

The persistent JMS storage will be a KahaDB database under the
"dataDirectory". I have verified that it actually does persist
and retransmit messages that were sent before a restart and
consumed afterwards. This works for me. I don't know how to
achieve JDBC persistence.

--
Bjorn Danielsson
Cuspy Code AB

Reply | Threaded
Open this post in threaded view
|

Re: JMS and peristent messages

Jacek Laskowski-2
On Fri, Sep 23, 2011 at 8:04 PM, Bjorn Danielsson
<[hidden email]> wrote:

> Yet again, ${openejb.base} doesn't work

Hi,

Interesting use case I've never thought about myself! I'm glad people
enjoy trying openejb out in such use cases (one may have not imagined
openejb would be capable of running in). In such situations I wish I
could leave everything aside and start hacking. Before pursuing it
further...

What's the version of openejb? Would you mind upgrading when a patched
version comes out?

Jacek

--
Jacek Laskowski
Java EE, functional languages and IBM WebSphere - http://blog.japila.pl
Warszawa JUG conference = Confitura (formerly Javarsovia) :: http://confitura.pl
Reply | Threaded
Open this post in threaded view
|

Re: JMS and peristent messages

Bjorn Danielsson
Jacek Laskowski <[hidden email]> wrote:
> On Fri, Sep 23, 2011 at 8:04 PM, Bjorn Danielsson
> <[hidden email]> wrote:
>> Yet again, ${openejb.base} doesn't work
>
> What's the version of openejb? Would you mind upgrading when a patched
> version comes out?

My results are with 3.2.0-SNAPSHOT from 20110920.

I don't know about the original poster, but I don't mind upgrading
since I am already running a pre-release.

--
Bjorn Danielsson
Cuspy Code AB

Reply | Threaded
Open this post in threaded view
|

how to use openejb.embedded.remoteable in TomEE

Frank Brown
In reply to this post by Bjorn Danielsson
I am new to OpenEJB.
 
I have deployed a legacy EJBModule several different ways, with varying degrees of success:
 
1. deployed myEJB.jar to OpenEJB standalone server.  Accessed the EJB's remotely from a webapp and a java client.
This works fairly well, although I haven't achieved 100% success from all clients.
 
2. installed TomEE, deployed myWebApp.war to TomEE, with myEJB.jar in myWebApp/WEB-INF/lib.
I am able to access the EJB's from the webapp using both LocalInitialContextFactory and  RemoteInitialContextFactory,
but I can't access the EJB's from the java client using  RemoteInitialContextFactory.
 
 
When I attempt to access an EJB from the client (on the same computer), I get this error:
 
 
In CLIENT'S STDERR.LOG:
org.apache.openejb.client.StickyConnectionStrategy connect
WARNING: Failover: Cannot connect to server(s):ejbd://localhost:4201 Exception: Cannot connect to server 'ejbd://localhost:4201'.  
Check that the server is started and that the specified serverURL is correct..  Trying next.
 
In CLIENT'S STDOUT.LOG:
 
**getSecurityBean(): ProviderURL:ejbd://localhost:4201
**getSecurityBean(): ContextFactory:org.apache.openejb.client.RemoteInitialContextFactory
Looking up context: gov.stancounty.itsabouttime.ejb.SecurityHome
EXCEPTION: ==========Application.getSecurityBean()==============
Cannot lookup '/gov.stancounty.itsabouttime.ejb.SecurityHome'.
javax.naming.NamingException: Cannot lookup '/gov.stancounty.itsabouttime.ejb.SecurityHome'.
[Root exception is java.rmi.RemoteException: Unable to connect; nested exception is:
 java.rmi.RemoteException: Cannot connect to any servers: Server #0: ejbd://localhost:4201]
 at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:224)
 at javax.naming.InitialContext.lookup(Unknown Source)
 at gov.stancounty.itsabouttime.util.Application.getSecurityBean(Application.java:607)
 at gov.stancounty.itsabouttime.gui.Login.init(Login.java:151)
 at gov.stancounty.itsabouttime.gui.Login.<init>(Login.java:89)
 at gov.stancounty.itsabouttime.gui.AdminConsole.main(AdminConsole.java:1110)
* openejb log shows it deploys jndiname=gov.stancounty.itsabouttime.ejb.SecurityHome
* I can go to http://localhost:8080/openejb and browse the EJB's and see it and invoke it.
* I access this same bean from the webapp without any problem.
* I get a similar error when I try this provider URL: http://localhost:4204/ejb 
 
I'm guessing it has to do with either or both of these:
1.  openejb.embedded.remoteable (where does this property go?  How do I tell if openejb is finding it?)
2.  hostname/ipaddress that openejb binds to?
 
Can anyone shed some light on this problem?  
 
 
Reply | Threaded
Open this post in threaded view
|

Re: how to use openejb.embedded.remoteable in TomEE

Romain Manni-Bucau
hi,

in tomcat/tomee we use openejb webapp to do it, try http://localhost:<tomcat
port - probably 8080>/openejb/ejb/

- Romain

2011/9/29 Frank Brown <[hidden email]>

> I am new to OpenEJB.
>
> I have deployed a legacy EJBModule several different ways, with varying
> degrees of success:
>
> 1. deployed myEJB.jar to OpenEJB standalone server.  Accessed the EJB's
> remotely from a webapp and a java client.
> This works fairly well, although I haven't achieved 100% success from all
> clients.
>
> 2. installed TomEE, deployed myWebApp.war to TomEE, with myEJB.jar in
> myWebApp/WEB-INF/lib.
> I am able to access the EJB's from the webapp using both
> LocalInitialContextFactory and  RemoteInitialContextFactory,
> but I can't access the EJB's from the java client using
>  RemoteInitialContextFactory.
>
>
> When I attempt to access an EJB from the client (on the same computer), I
> get this error:
>
>
> In CLIENT'S STDERR.LOG:
> org.apache.openejb.client.StickyConnectionStrategy connect
> WARNING: Failover: Cannot connect to server(s):ejbd://localhost:4201
> Exception: Cannot connect to server 'ejbd://localhost:4201'.
> Check that the server is started and that the specified serverURL is
> correct..  Trying next.
>
> In CLIENT'S STDOUT.LOG:
>
> **getSecurityBean(): ProviderURL:ejbd://localhost:4201
> **getSecurityBean():
> ContextFactory:org.apache.openejb.client.RemoteInitialContextFactory
> Looking up context: gov.stancounty.itsabouttime.ejb.SecurityHome
> EXCEPTION: ==========Application.getSecurityBean()==============
> Cannot lookup '/gov.stancounty.itsabouttime.ejb.SecurityHome'.
> javax.naming.NamingException: Cannot lookup
> '/gov.stancounty.itsabouttime.ejb.SecurityHome'.
> [Root exception is java.rmi.RemoteException: Unable to connect; nested
> exception is:
>  java.rmi.RemoteException: Cannot connect to any servers: Server #0:
> ejbd://localhost:4201]
>  at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:224)
>  at javax.naming.InitialContext.lookup(Unknown Source)
>  at
> gov.stancounty.itsabouttime.util.Application.getSecurityBean(Application.java:607)
>  at gov.stancounty.itsabouttime.gui.Login.init(Login.java:151)
>  at gov.stancounty.itsabouttime.gui.Login.<init>(Login.java:89)
>  at
> gov.stancounty.itsabouttime.gui.AdminConsole.main(AdminConsole.java:1110)
> * openejb log shows it deploys
> jndiname=gov.stancounty.itsabouttime.ejb.SecurityHome
> * I can go to http://localhost:8080/openejb and browse the EJB's and see
> it and invoke it.
> * I access this same bean from the webapp without any problem.
> * I get a similar error when I try this provider URL:
> http://localhost:4204/ejb
>
> I'm guessing it has to do with either or both of these:
> 1.  openejb.embedded.remoteable (where does this property go?  How do I
> tell if openejb is finding it?)
> 2.  hostname/ipaddress that openejb binds to?
>
> Can anyone shed some light on this problem?
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: how to use openejb.embedded.remoteable in TomEE

jgallimore
In reply to this post by Frank Brown
Hi Frank,

I think all you need to do is use http://localhost:8080/openejb/ejb as the
provider URL (swap 8080 for your http port if its different):

Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
p.setProperty(Context.PROVIDER_URL, "http://localhost:8080/openejb/ejb");
InitialContext ic = new InitialContext(p);

Hope that helps.

Jon

On Thu, Sep 29, 2011 at 9:29 PM, Frank Brown <[hidden email]> wrote:

> I am new to OpenEJB.
>
> I have deployed a legacy EJBModule several different ways, with varying
> degrees of success:
>
> 1. deployed myEJB.jar to OpenEJB standalone server.  Accessed the EJB's
> remotely from a webapp and a java client.
> This works fairly well, although I haven't achieved 100% success from all
> clients.
>
> 2. installed TomEE, deployed myWebApp.war to TomEE, with myEJB.jar in
> myWebApp/WEB-INF/lib.
> I am able to access the EJB's from the webapp using both
> LocalInitialContextFactory and  RemoteInitialContextFactory,
> but I can't access the EJB's from the java client using
>  RemoteInitialContextFactory.
>
>
> When I attempt to access an EJB from the client (on the same computer), I
> get this error:
>
>
> In CLIENT'S STDERR.LOG:
> org.apache.openejb.client.StickyConnectionStrategy connect
> WARNING: Failover: Cannot connect to server(s):ejbd://localhost:4201
> Exception: Cannot connect to server 'ejbd://localhost:4201'.
> Check that the server is started and that the specified serverURL is
> correct..  Trying next.
>
> In CLIENT'S STDOUT.LOG:
>
> **getSecurityBean(): ProviderURL:ejbd://localhost:4201
> **getSecurityBean():
> ContextFactory:org.apache.openejb.client.RemoteInitialContextFactory
> Looking up context: gov.stancounty.itsabouttime.ejb.SecurityHome
> EXCEPTION: ==========Application.getSecurityBean()==============
> Cannot lookup '/gov.stancounty.itsabouttime.ejb.SecurityHome'.
> javax.naming.NamingException: Cannot lookup
> '/gov.stancounty.itsabouttime.ejb.SecurityHome'.
> [Root exception is java.rmi.RemoteException: Unable to connect; nested
> exception is:
>  java.rmi.RemoteException: Cannot connect to any servers: Server #0:
> ejbd://localhost:4201]
>  at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:224)
>  at javax.naming.InitialContext.lookup(Unknown Source)
>  at
> gov.stancounty.itsabouttime.util.Application.getSecurityBean(Application.java:607)
>  at gov.stancounty.itsabouttime.gui.Login.init(Login.java:151)
>  at gov.stancounty.itsabouttime.gui.Login.<init>(Login.java:89)
>  at
> gov.stancounty.itsabouttime.gui.AdminConsole.main(AdminConsole.java:1110)
> * openejb log shows it deploys
> jndiname=gov.stancounty.itsabouttime.ejb.SecurityHome
> * I can go to http://localhost:8080/openejb and browse the EJB's and see
> it and invoke it.
> * I access this same bean from the webapp without any problem.
> * I get a similar error when I try this provider URL:
> http://localhost:4204/ejb
>
> I'm guessing it has to do with either or both of these:
> 1.  openejb.embedded.remoteable (where does this property go?  How do I
> tell if openejb is finding it?)
> 2.  hostname/ipaddress that openejb binds to?
>
> Can anyone shed some light on this problem?
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: how to use openejb.embedded.remoteable in TomEE

Frank Brown
That's too easy!
 
Now why didn't I think of that!?
 
Works great;  Problem solved.  Thank you both,  Romain and Jonathan!

>>> On 9/29/2011 at  1:36 PM, Jonathan Gallimore <[hidden email]> wrote:
Hi Frank,

I think all you need to do is use http://localhost:8080/openejb/ejb as the
provider URL (swap 8080 for your http port if its different):

Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
p.setProperty(Context.PROVIDER_URL, "http://localhost:8080/openejb/ejb");
InitialContext ic = new InitialContext(p);

Hope that helps.

Jon

On Thu, Sep 29, 2011 at 9:29 PM, Frank Brown <[hidden email]> wrote:

> I am new to OpenEJB.
>
> I have deployed a legacy EJBModule several different ways, with varying
> degrees of success:
>
> 1. deployed myEJB.jar to OpenEJB standalone server.  Accessed the EJB's
> remotely from a webapp and a java client.
> This works fairly well, although I haven't achieved 100% success from all
> clients.
>
> 2. installed TomEE, deployed myWebApp.war to TomEE, with myEJB.jar in
> myWebApp/WEB-INF/lib.
> I am able to access the EJB's from the webapp using both
> LocalInitialContextFactory and  RemoteInitialContextFactory,
> but I can't access the EJB's from the java client using
>  RemoteInitialContextFactory.
>
>
> When I attempt to access an EJB from the client (on the same computer), I
> get this error:
>
>
> In CLIENT'S STDERR.LOG:
> org.apache.openejb.client.StickyConnectionStrategy connect
> WARNING: Failover: Cannot connect to server(s):ejbd://localhost:4201
> Exception: Cannot connect to server 'ejbd://localhost:4201'.
> Check that the server is started and that the specified serverURL is
> correct..  Trying next.
>
> In CLIENT'S STDOUT.LOG:
>
> **getSecurityBean(): ProviderURL:ejbd://localhost:4201
> **getSecurityBean():
> ContextFactory:org.apache.openejb.client.RemoteInitialContextFactory
> Looking up context: gov.stancounty.itsabouttime.ejb.SecurityHome
> EXCEPTION: ==========Application.getSecurityBean()==============
> Cannot lookup '/gov.stancounty.itsabouttime.ejb.SecurityHome'.
> javax.naming.NamingException: Cannot lookup
> '/gov.stancounty.itsabouttime.ejb.SecurityHome'.
> [Root exception is java.rmi.RemoteException: Unable to connect; nested
> exception is:
>  java.rmi.RemoteException: Cannot connect to any servers: Server #0:
> ejbd://localhost:4201]
>  at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:224)
>  at javax.naming.InitialContext.lookup(Unknown Source)
>  at
> gov.stancounty.itsabouttime.util.Application.getSecurityBean(Application.java:607)
>  at gov.stancounty.itsabouttime.gui.Login.init(Login.java:151)
>  at gov.stancounty.itsabouttime.gui.Login.<init>(Login.java:89)
>  at
> gov.stancounty.itsabouttime.gui.AdminConsole.main(AdminConsole.java:1110)
> * openejb log shows it deploys
> jndiname=gov.stancounty.itsabouttime.ejb.SecurityHome
> * I can go to http://localhost:8080/openejb and browse the EJB's and see
> it and invoke it.
> * I access this same bean from the webapp without any problem.
> * I get a similar error when I try this provider URL:
> http://localhost:4204/ejb 
>
> I'm guessing it has to do with either or both of these:
> 1.  openejb.embedded.remoteable (where does this property go?  How do I
> tell if openejb is finding it?)
> 2.  hostname/ipaddress that openejb binds to?
>
> Can anyone shed some light on this problem?
>
>
>