Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-3995

Let spring Integration give access to an in-memory queue channel for different jvm

    XMLWordPrintable

    Details

      Description

      Hello

      I have the following queue channel

      <int:channel id="channel">
      	<int:queue capacity="4"  />
      </int:channel>
      

      According with the reference documentation QueueChannel Configuration says:

      Persistent QueueChannel Configuration

      Since a QueueChannel provides the capability to buffer Messages, but does so in-memory only by default, it also introduces a possibility that Messages could be lost in the event of a system failure

      I have two Main classes

      public class MainProducer {
      
      	private static final Logger logger = LoggerFactory.getLogger(MainProducer.class.getSimpleName());
      	
      	public static void main(String[] args) throws Exception {
      		
      		logger.info("{} ini....",MainProducer.class.getSimpleName());
      		
      		ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(ProducerCentralConfig.class);
      				
      		logger.info("Producer...");
      		
      		MessageProducer messageProducer = applicationContext.getBean(MessageProducer.class);
      		
      		for(int i=0; i<=3; i++){
      			messageProducer.sendMessage();
      		}
      				
      		Thread.sleep(20000);
      		
      		applicationContext.close();
      		
      		logger.info("{} end....",MainProducer.class.getSimpleName());
      		
      	}
      }
      

      it works fine

      The other is:

      public class MainConsumer {
      
      	private static final Logger logger = LoggerFactory.getLogger(MainConsumer.class.getSimpleName());
      	
      	public static void main(String[] args) throws Exception {
      		
      		logger.info("{} ini....",MainConsumer.class.getSimpleName());
      		
      		ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConsumerCentralConfig.class);
      
      		MessageConsumer messageConsumer = applicationContext.getBean(MessageConsumer.class);
      		
      		for(int i=0; i<=3; i++){
      			Thread.sleep(2000);
      			messageConsumer.receiveMessage();
      			if(i==3)
      				break;
      		}
      		
      		applicationContext.close();
      		
      		logger.info("{} end....",MainConsumer.class.getSimpleName());
      		
      	}	
      }
      

      It hangs or remain blocked...

      But If I have other Main class merging the producer and consumer

      public class MainProducerConsumer {
      
      	private static final Logger logger = LoggerFactory.getLogger(MainProducerConsumer.class.getSimpleName());
      	
      	public static void main(String[] args) throws Exception {
      		
      		logger.info("{} ini....",MainProducerConsumer.class.getSimpleName());
      		
      		ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(ProducerConsumerCentralConfig.class);
      				
      		logger.info("Producer...");
      		
      		MessageProducer messageProducer = applicationContext.getBean(MessageProducer.class);
      		
      		for(int i=0; i<=3; i++){
      			messageProducer.sendMessage();
      		}
      				
      		logger.info("Consumer...");
      		MessageConsumer messageConsumer = applicationContext.getBean(MessageConsumer.class);
      		
      		for(int i=0; i<=3; i++){
      			Thread.sleep(2000);
      			messageConsumer.receiveMessage();
      			if(i==3)
      				break;
      		}
      		
      		Thread.sleep(20000);
      		
      		
      		
      		applicationContext.close();
      		
      		logger.info("{} end....",MainProducerConsumer.class.getSimpleName());
      		
      	}
      }
      
      

      All works fine...

      Therefore I am assuming that MainProducer and MainConsumer do not share the same jam, and thus MainConsumer practically stays blocked since the queue channel is not share between the Producer and Consumer.

      (1) Is there a way through Spring Integration to let two main classes (Producer and Consumer) share the same JVM?
      (2) Is there a tool or option through Spring Integration to let me see the current capacity of the queue channel? It for testing and development purposes. It to let me do a monitoring through visualvm. With visualvm I am only able to see the "Threads" but nothing about some queue.

        Attachments

          Activity

            People

            Assignee:
            grussell Gary Russell
            Reporter:
            dr_pompeii Manuel Jordan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: