Results 1 to 5 of 5

Thread: Stop and start consuming message from a queue MQ

  1. #1
    Join Date
    Aug 2010
    Posts
    11

    Default 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. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    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.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Aug 2010
    Posts
    11

    Default

    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.

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,037

    Default

    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.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Aug 2010
    Posts
    11

    Default

    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()));
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •