1 2 Previous Next 21 Replies Latest reply on Jul 11, 2002 3:30 PM by jsvazic

    Simple MDB example fails silently

    salkin

      Hi-

      If anyone can give me a leg up on a simple example I would appreciate it. I have a client ValidationProxy with a perform() method : all it does it put an ObjectMessage on the validateQueue. This seems to work, the code runs w/o exceptions. I can see the validateQueue in the jboss admin console, the directory in db, etc. Now, there is a message-driven bean ValidateBean that is supposed to be listening to this queue - the first line of onMessage() has a System.out.println(), and then further processing. No println appears in the console, and the further processing (which changes a database) does not occur. But I don't see messages stacking up in the filesystem anywhere.

      Does this look familiar to anyone? I can't imagine that the queue is bad, or the client code (called from a struts action) should have exceptions. But the MDB configuration could not be simpler - just get the queue name right in jboss.xml, and it's right.

      I actually bought the jboss book (for 2.4.5, even though I'm running 3.0.0) just to try to solve this, but it hasn't helped. I hope someone here can lend a hand. :)

        • 1. Re: Simple MDB example fails silently
          salkin

          I'll just add that I originally was deploying the MDB in one jar, and the web app in a separate war, on the theory that they didn't need to be packaged together since they never looked each other up, and only communicated via the queue. However, even when deployed together in an ear I still see no signs of life from the mdb. I don't see the out.printlns in its lifecycle methods (create(), etc.) or at the start of onMessage(). Thanks again for any insight.

          • 2. Re: Simple MDB example fails silently
            joelvogt

            Can you post your mdb config? This will probably lead to the answer

            • 3. Re: Simple MDB example fails silently
              salkin

              OK, thanks for listening :) I didn't post it because it seems trivial, but I guess that's how things usually go.

              Excerpt from ejb-jar.xml
              ------------------------
              <message-driven >
              validate mdb
              <display-name>ValidateBean</display-name>
              <ejb-name>ejb/ValidateBean</ejb-name>
              <ejb-class>
              com.XXXXXX.service.validate.ValidateBean
              </ejb-class>
              <transaction-type>Container</transaction-type>
              <acknowledge-mode>Auto-acknowledge</acknowledge-mode>
              <message-driven-destination>
              <destination-type>javax.jms.Queue</destination-type>
              <subscription-durability>
              Durable <!-- tried non also -->
              </subscription-durability>
              </message-driven-destination>
              </message-driven>

              Excerpt from jboss.xml
              ----------------------
              <message-driven>
              <ejb-name>ejb/ValidateBean</ejb-name>
              <destination-jndi-name>
              queue/validateQueue
              </destination-jndi-name>
              </message-driven>

              I have verified by using the admin interface, looking at the log, and running my client that the queue exists and is deployed under the jndi name "queue/validateQueue".

              I hope this doesn't prove too embarassing, but in any event I hope this help uncover the mysterious "silent bean" syndrome. :)

              • 4. Re: Simple MDB example fails silently
                joelvogt

                I can't see any big problem, but maybe try these small changes:
                <message-driven >
                validate mdb
                <display-name>ValidateBean</display-name>
                <ejb-name>ejb/ValidateBean</ejb-name>
                <ejb-class>
                com.XXXXXX.service.validate.ValidateBean
                </ejb-class>
                <transaction-type>Container</transaction-type>
                <acknowledge-mode>AUTO_ACKNOWLEDGE</acknowledge-mode>
                <message-driven-destination>
                <destination-type>javax.jms.Queue</destination-type>
                </message-driven-destination>
                </message-driven>

                and ...

                <message-driven>
                <ejb-name>ejb/ValidateBean</ejb-name>
                <configuration-name>
                Standard Message Driven Bean
                </configuration-name>
                <destination-jndi-name>
                queue/validateQueue
                </destination-jndi-name>
                </message-driven>

                If this doesn't help, the next thing to check is your server log when the mdb starts up (for error messages)


                Oh, and make sure ejb-jar.xml has a section

                <container-transaction>

                <ejb-name>ejb/ValidateBean</ejb-name>
                <method-name>*</method-name>

                <trans-attribute>NotSupported</trans-attribute>
                </container-transaction>

                or similar

                • 5. Re: Simple MDB example fails silently
                  salkin

                  OK, thank you. I made those changes, and redeployed. Here's a snip from the server log:
                  09:37:30,929 INFO [EjbModule] Creating
                  09:37:30,969 INFO [EjbModule] Deploying ejb/ValidateBean
                  09:37:32,521 INFO [EjbModule] Created
                  09:37:32,521 INFO [EjbModule] Starting
                  09:37:32,531 INFO [EjbModule] Started

                  which looks fine to me. AFter those lines, no more ejb messages or errors of any kind appear. The proxy sends the message and gets the message id which it displays:
                  09:40:24,749 INFO [STDOUT] ValidateProxy::message sent-id ID:2-10262220247391

                  and that's it. Here's the ValidateBean, edited for length
                  :
                  public class ValidateBean implements MessageDrivenBean, MessageListener {

                  private transient MessageDrivenContext c;

                  public void setMessageDrivenContext(MessageDrivenContext c) { this.c = c; }

                  public void ejbCreate() {
                  System.out.println("ValidateBean::created");
                  }

                  public void ejbRemove() {
                  System.out.println("ValidateBean::removed");
                  }

                  public void onMessage(Message m) {
                  try {
                  System.out.println("ValidateBean::processing message id " + m.getJMSMessageID());
                  if (m instanceof ObjectMessage) {
                  ObjectMessage om = (ObjectMessage)m;
                  Object o = om.getObject();

                  if (o instanceof Account) {
                  Account a = (Account)o;
                  System.out.println("ValidateBean::recieved account " + a.toString());
                  }
                  }
                  catch (JMSException e) {
                  // FIXME SLS
                  e.printStackTrace();
                  }
                  }

                  Anything jump out? In the actual bean if an account is recieved a change is made in the database, so I can see that it's not just not printing, it's not acting at all.

                  • 6. Re: Simple MDB example fails silently
                    joelvogt

                    Mok, two small things, not sure if they will fix it, but should be getting closer,

                    private transient MessageDrivenContext c;
                    to
                    private MessageDrivenContext c;

                    public void ejbRemove() {
                    System.out.println("ValidateBean::removed");
                    }

                    to

                    public void ejbRemove()
                    {
                    System.out.println("ValidateBean::removed");
                    ctx=null;
                    }

                    • 7. Re: Simple MDB example fails silently
                      joelvogt

                      oh and declare setMessageDrivenContext to throw an
                      EJBException

                      public void setMessageDrivenContext(MessageDrivenContext c)
                      throws EJBException

                      • 8. Re: Simple MDB example fails silently
                        salkin

                        Hi,

                        Thanks again, I tried those changes, and still no luck. Now I am thinking that it must be a security issue. In other words, if you don't see anything wrong with the bean or the deployment, maybe its not allowed to get the messages, or maybe the JMS system isn't allowed to deliver them. I am using a custom form-based authentication that doesn't go through jboss at all (the app was originally developed on tomcat, and the need for asynch in the back end was discovered in development). So, I have no JAAS "role" or anything in the client or in the MDB. I did give "guest" both read and write privileges on the queue in the jbossmq-destintations-service.xml.

                        How about that, does that sound plausible? If the client was forbidden to add the message to the queue, would I be able to get a jms message id from the message that didn't get sent? Or if the MDB wasn't allowed to read messages (or the queue won't deliver them) would that be what a misconfigured security set up failure mode looks like?

                        I'm at the point now where I'll paypal $50 to anyone who can tell me what's wrong by about 6PM EST tomorrow because I'm going out of town Thur-Sun and I really want to have this working when I do. I have burned *way* too many cycles looking at this.

                        Anyway, , thanks again very much. :)

                        • 9. Re: Simple MDB example fails silently
                          joelvogt

                          Hmm, maybe...
                          My advice at this stage is to forget the mdb for a moment and just write a quick jms listener client that connects to your queueand umm listens. Theres always a bit of mdb config stuffing around but if your client doesn't work then the problem most likely is something like security or jms service config. If it does work then you know it's just the mdb.

                          • 10. Re: Simple MDB example fails silently
                            joelvogt

                            failing this, take our those security settings and give it another shot. (Go back to original service xml if available). From the sounds of it mdb config is correct, so must be something in jboss setup.

                            • 11. Re: Simple MDB example fails silently
                              salkin

                              Just an update: thanks for the additional tips, I wrote a small Queue listener standalone program and it does not receive any messages either. It's basically a copy of the code in the JMS tutorial just so I would be sure not to introduce the same mistake if I was doing something wrong in the bean.

                              Anyway, I ended up having to a lot of jboss jars to the CP abut it now binds and sees nothing. I'll start tampering with security settings next.

                              Thanks again,

                              S-

                              • 12. Re: Simple MDB example fails silently
                                jsvazic

                                Try this last thing. Edit your original code that sends the message to the queue and make sure that the transaction flag is set to "false" not "true". This should fix the problem.

                                • 13. Re: Simple MDB example fails silently
                                  salkin

                                  OK now it works. I wrote another client to send messages and it could send to the test receiver and also to the bean. The test sender was cloned again from the JMS tutorial so I could avoid any of my own mistakes. The sender differed from my code only in that the call to QueueConnection.createQueueSession() I was asking for transacted=true, and the tutorial code asked for false. Changing my code to not ask for transacted made it work.

                                  Now I don't know why, and although I'd like to, this deadline is climbing up my neck, so I'll have to wait to study it. In the meantime, if you send me your email to steve "at" salkin "dot" org I'll paypal you the money. You've been really helpful to me and I'd like to show my appreciation. If you can do this today I'll do it tonight, or else it won't be until I get back on Monday.

                                  Thanks again!
                                  S-

                                  • 14. Re: Simple MDB example fails silently
                                    jsvazic

                                    Welcome to the world of Open Source! Payment not required. ;-)

                                    1 2 Previous Next