6 Replies Latest reply on Aug 5, 2013 6:41 AM by sketcha

    Jboss 7.2 Issue with hornetqueue JMS while shutting down the server

    sketcha

      Hi ,

      I have an application which uses JMS to communicate with clients.

      The application needs to sendout notifications to client while any statechange is being done like bean initialization and destruction even including server shutdown.

      we are using beans which are decorated with @Postconstruct and @Predestroy annotation for this purpose.

      whil the serverbeing shutdown, the @Predestroy metod is getting invoked and we are trying to send a JMS message indicating the bean destruction.

      However this is not working as the Horentqueus is already stopped  and the Topic and Queues are shutdown prior to application.

      Is there any way i could delay the shutdown of hornetqueue topics and queues?

       

      Thanks,

      Best Regards,

      Keshava

        • 1. Re: Jboss 7.2 Issue with hornetqueue JMS while shutting down the server
          sfcoy

          Do these annotated beans use @Resource to get references to the message destinations?

           

          JBossAS tries to use these to order startup and shutdown correctly.

          • 2. Re: Jboss 7.2 Issue with hornetqueue JMS while shutting down the server
            sketcha

            Not directly. I am using the @Resource to get reference of message destination in a utility class which will be invoked from these beans

            • 3. Re: Jboss 7.2 Issue with hornetqueue JMS while shutting down the server
              sfcoy

              If the utility class is injected (@EJB?) then the dependency graph should still work.

               

              Is this how you're getting your utility class reference?

              • 4. Re: Jboss 7.2 Issue with hornetqueue JMS while shutting down the server
                sketcha

                Hi, Thanks for the answer. earlier i had wrongly mentioned that @Resource annotation But we are using Jndi Lookup to obtain message destination reference. This is how my Code snippet looks like.

                My utility class

                public class EventPublisher implements EventPublisherIf {

                          private static final String topicName = "topic/eventTopic";

                          private Context jndiContext;

                          private TopicConnectionFactory topicConnectionFactory;

                          private TopicConnection topicConnection;

                          private Topic topic;

                          private TopicPublisher topicPublisher;

                          private TopicSession topicSession = null;

                          private ObjectMessage objectMessage;

                          private static EventPublisherIf eventPublisher;

                          private boolean sessionActive = true;

                 

                 

                          public static synchronized EventPublisherIf getEventPublisher() {

                                    if (eventPublisher == null) {

                                              eventPublisher = new EventPublisher();

                                                                                             lookUpTopic();

                                    }

                                    return eventPublisher;

                          } 

                          private void lookUpTopic() {

                               try {

                                                                                  jndiContext = new InitialContext();

                                              topicConnectionFactory = (TopicConnectionFactory) jndiContext

                                                                  .lookup("ConnectionFactory");

                                              topic = (Topic) jndiContext.lookup(topicName);

                                    } catch (NamingException e) {

                                              log.error("Failed to lookup topic", e);

                                    }

                               }

                 

                          public void createTopicConnection() {

                                   try{

                                             try {

                                                        topicConnection = topicConnectionFactory.createTopicConnection("user","password");

                                              } catch (JMSSecurityException e) {

                                                    

                                                        topicConnection = topicConnectionFactory

                                                                            .createTopicConnection();

                                              }

                                              topicConnection.setExceptionListener(new JmsExceptionHandler());

                                              topicSession = topicConnection.createTopicSession(false,

                                                                  Session.AUTO_ACKNOWLEDGE);

                                              topicPublisher = topicSession.createPublisher(topic);

                                              sessionActive = true;

                                    } catch (JMSException e) {

                                              sessionActive = false;

                                          }

                          }

                         public synchronized void publishEvent(BaseEvent event) {

                                    try {

                                              if (!sessionActive) {

                                                        createTopicConnection();

                                              }

                                              if (sessionActive) {

                                                        objectMessage = topicSession.createObjectMessage(event);

                                                     topicPublisher.publish(objectMessage);

                 

                                              }

                                    } catch (JMSException e) {

                                              sessionActive = false;                             

                                    }

                          }

                }

                 

                and my bean code

                 

                @Stateless

                @Remote(Processor.class)

                public class ProcessorBean implements Processor{

                 

                @PostConstruct

                public void initProcessor(){

                EventPublisher.getEventPublisher().publishEvent(new BaseEvent("ProcessorInit");

                }

                 

                @PostConstruct

                public void stopProcessor(){

                EventPublisher.getEventPublisher().publishEvent(new BaseEvent("ProcessorShutdown");

                }

                 

                public void process(){

                }

                }

                 

                Kindly let me know if i need to change anything to make it work with dependency

                • 5. Re: Jboss 7.2 Issue with hornetqueue JMS while shutting down the server
                  sfcoy

                  A short term cheat to begin might be to add

                  {code:java}@Resource(lookup="topic/eventTopic")

                  private Topic topic;{code}

                  to your ProcessorBean.

                   

                  This should make your EJB dependent upon the topic even if it's unused.

                   

                  In the medium term, convert your EventPublisher into another stateless session bean (using @Resource and getting rid of the JNDI lookups) and then inject it into ProcessorBean and any other clients.

                  • 6. Re: Jboss 7.2 Issue with hornetqueue JMS while shutting down the server
                    sketcha

                    Thank Stephen.. It worked for me