Announcement Announcement Module
Collapse
No announcement yet.
Stop and start consuming message from a queue MQ Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stop and start consuming message from a queue MQ

    Im running spring in websphere and connecting to MQ queues where I'm trying to stop consuming messages from a the queue between certain times. In order for me to do this I'm shutting down the queue listener and then starting it up, here is a snippet of my code.

    Code:
    //defaultListenerContainer is an instance of org.springframework.jms.listener.DefaultMessageListenerContainer;
    defaultListenerContainer.shutdown();
    		
    new Timer().schedule(new TimerTask() {
    	public void run() {
                    defaultListenerContainer.initialize();
    	        defaultListenerContainer.start();
    	}}, delay);
    }
    The problem is when it starts back up I won't receive any message unless I explicit create a new connection. like so
    Code:
    defaultListenerContainer.getConnectionFactory().createConnection().start();
    With the connection created I can consume messages but, when I monitor the connection pool in websphere, I notice this connection is not returned back to the pool, causing a leak.

    Anyone have any ideas on what I can do?

    P.S.. Websphere will not allow me to call stop on the listener. i.e
    Code:
    defaultListenerContainer.stop()
    websphere says stop is not allowed. Further research I found on the IBM website saying I can't call this command in a j2ee container.

  • #2
    Websphere will not allow me to call stop on the listener.
    Not sure what you mean by that; you should call stop() not shutdown(). WAS doesn't know anything about the DMLC.

    When running in WAS, be sure to use a WorkManagerTaskExecutor and/or TimerMnagerTaskScheduler rather than any other kind of TE or TS - WAS doesn't allow arbitrary thread creation.

    Comment


    • #3
      wow super quick response thanks

      This is the debug message I get When I call stop().
      DEBUG mySchedular-1 org.springframework.jms.listener.DefaultMessageLis tenerContainer - Ignoring Connection stop exception - assuming already stopped: javax.jms.IllegalStateException: Method stop not permitted

      http://www.ibm.com/developerworks/library/j-getmess/ This page talks about restricted methods see "J2EE restrictions on JMS usage"

      I will try your suggestion and report back.

      Comment


      • #4
        Right; but that message is coming out under DEBUG only; it's just saying the container is ignoring the connection.stop() call - because WAS might share it with other apps.

        Just ignore it.

        Comment


        • #5
          Perfect, using spring taskschedule did the trick and calling stop and start worked as expected. Thanks for your help.

          Code:
          @Scheduled(cron="${schedule.from}")
          public void process() {
          		
          	provisionerListenerContainer.stop();
          		
          	taskScheduler.schedule(new Runnable() {
          		public void run() {
          			 provisionerListenerContainer.start();
          		}
          	}, DateUtils.addMilliseconds(new Date(), delay.intValue()));
          }

          Comment

          Working...
          X