Announcement Announcement Module
Collapse
No announcement yet.
Setting JMS broker URL during startup? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting JMS broker URL during startup?

    Hey folks,
    I have a very simple and standard JMS client using JmsTemplate and DefaultMessageListenerContainer in combination with ActiveMQ 5.2

    I have noticed that the time my client takes to initialize varies a great deal. This can be between a few milliseconds to a few seconds.

    This led in some cases to a failure when setting a custom broker during start up of the application.

    Question: What is the correct time and place to set a custom broker on application start up?

    See my code below, the way I can make it work is by calling
    listenerContainer.initialize()

    But I have the feeling there is a better way to do it.

    Code:
    	public static void main(String[] args) {
    		try {		
    			System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++ ");
    			processargs(args);
    
    			BeanFactory appContext = new XmlBeanFactory(new ClassPathResource(APPCONTEXT));					
    			XedocReceiver jmsReceiver = (XedocReceiver) appContext.getBean("jmsReceiver");				
    			DefaultMessageListenerContainer listenerContainer = (DefaultMessageListenerContainer) appContext.getBean("jmsContainer");
    			ActiveMQConnectionFactory jmsConnectionFactory = (ActiveMQConnectionFactory) appContext.getBean("jmsConnectionFactory");
    
    			if(		xedocJMSClientConfig.getBroker() != null &&
    					!xedocJMSClientConfig.getBroker().equals("") &&
    					!xedocJMSClientConfig.getBroker().equals(jmsConnectionFactory.getBrokerURL()) 
    			){
    				jmsConnectionFactory.setBrokerURL(xedocJMSClientConfig.getBroker());
    				listenerContainer.initialize();
    			}else{
    				System.out.println("Using default broker " +  jmsConnectionFactory.getBrokerURL() );
    			}
    			...
    TIA

    Jochen
Working...
X